Home > Blockchain >  Removing "\n" from columns name in Pandas dataFrame
Removing "\n" from columns name in Pandas dataFrame

Time:08-30

I have a CSV file having column names with line breaks when I read the file with pd.read_csv() it returns the column names like this Violent\ncrime\nrate. how do I replace \n with "_" for all these columns?

CodePudding user response:

Try:

df.columns = [c.replace("\n", "_") for c in df.columns]
print(df)
  • Related