I'm reading a csv file using pandas.read_csv()
. My csv file has headers with spaces at start or end like ' header1', 'header2 '
I want to trim that extra space at start/end. Is their a way to specify this using some arguments? If not how to achieve that in my resultant dataframe?
You could try with this, after reading the csv:
df.columns =[col.strip() for col in df.columns]
Same as:
df.rename(columns=lambda x: x.strip(), inplace=True)
Or this too:
df.columns=df.columns.str.strip()
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