Home > Enterprise >  pandas: remove the "," on the columns beginning when I save a Dataframe with .to_csv()
pandas: remove the "," on the columns beginning when I save a Dataframe with .to_csv()

Time:11-17

I'm saving my csv without errors with pandas but I have a problem on my columns name, there is a "," that I want to remove !

import pandas as pd
csv_path = "your\csv\path\and\filename.csv"
df = pd.DataFrame(data={'filename': [], 'words': []})
df.to_csv(path_or_buf=csv_path,index=False)

Visual_on_the_problem

I have ,filename,words but I just want filename,words

CodePudding user response:

You're code is right for Pandas 1.3.4:

# df = pd.DataFrame(data={'filename': [], 'words': []})
>>> print(df.to_csv())
,filename,words

>>> print(df.to_csv(index=False))
filename,words
  • Related