Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove Semicolon from array in python?

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
like image 573
Salman Shaukat Avatar asked May 30 '26 20:05

Salman Shaukat


2 Answers

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.

like image 121
MaxU - stop WAR against UA Avatar answered Jun 02 '26 08:06

MaxU - stop WAR against UA


Use str.rstrip:

df['Z-Axis'] = df['Z-Axis'].str.rstrip(";")
like image 32
jezrael Avatar answered Jun 02 '26 10:06

jezrael