Reputation: 61
def filter_csv(intputfile, outputfile):
df = pd.read_csv(intputfile,delimiter=',')
df = df.fillna('')
for index, row in df.iterrows():
print(index, row)
df.to_csv(outputfile)
When I run it, it reported some columns like below:
Unnamed: 27 NaN
Unnamed: 28 NaN
Unnamed: 29 NaN
Unnamed: 30 NaN
Unnamed: 31 NaN
However, each column in my csv file has a column name and I dont understand why it reports this. Does this harm?
Upvotes: 0
Views: 498
Reputation: 21
Are you reloading this a bunch of times?
df.to_csv
has index=True
as a default. This adds a column to the CSV Unnammed: X
(unless your index is named), for the index number.
Try by doing : df.to_csv(outputfile, index=False)
Upvotes: 1