I'm reading a csv file through pandas in python and the last column also includes ; how can i remove it. if i use delimiter as ; it does not work.
Example :
0 -0.22693644;
1 -0.22602014;
2 0.37201694;
3 -0.27763826;
4 -0.5549711;
Name: Z-Axis, dtype: object
I would use parameter comment:
df = pd.read_csv(file, comment=';')
NOTE: this will work properly only for the last column, as everything starting from the comment character till the end of string will be ignored
PS as a little bonus Pandas will treat such column as numeric one, not as a string.
Use str.rstrip:
df['Z-Axis'] = df['Z-Axis'].str.rstrip(";")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With