2

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
1
  • 3
    df['columnname'].str.rstrip(";")? Commented May 17, 2018 at 11:16

3 Answers 3

5

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.

Sign up to request clarification or add additional context in comments.

Comments

4

Use str.rstrip:

df['Z-Axis'] = df['Z-Axis'].str.rstrip(";")

Comments

2

Another option:

df['Z-Axis'] = df['Z-Axis'].str[:-1]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.