0

I have a dataset in a csv fomat

     id,    weight, height, wc, hc, sex,    birthdate
    187,     55.6,   154,   92, 89,   F,     21/11/1947

When I loaded it to to pandas dataframe, the row looks like this for sex and birthdate

\tF \t21/11/1947

How do I remove \t in front of the string value? I also need to compute the age of the person given from format dd/mm/yyyy.

*it seems that the csv file really has some white space or tabbed thats why \t was appearing. thanks for everyone who has given their answer

Reub
  • 665
  • 2
  • 18
  • 35
  • Are you using [`.read_csv`](https://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html)? – 9000 Mar 12 '18 at 19:19
  • 1
    If you are you using `read_csv()`, you can probably use [`sep='\s*,\s*'`](https://stackoverflow.com/a/35781099/5858851). – pault Mar 12 '18 at 19:20
  • 2
    those are better options, but for completeness, you should be able to do something like `df['birthdate'] = df.birthrate.str.strip()` to do vectorized string operations.... – Corley Brigman Mar 12 '18 at 19:23

0 Answers0