To delete part of a string in a pandas DataFrame column, you can use the .str.replace()
method. Here's an example:
main.py266 chars12 lines
This will remove the string 'Johnson' from the 'Name' column in the DataFrame, resulting in:
main.py80 chars5 lines
In the example, we use the .str.replace()
method to replace 'Johnson' with an empty string ('') in the 'Name' column. Note that this operation modifies the original DataFrame.
If you want to delete parts of a string using a specific pattern or regular expression, you can also use the .str.replace()
method with regex. For more advanced string manipulations, you might consider using the .str.extract()
method or applying a custom function to the column.
gistlibby LogSnag