Kalyan N
Kalyan N

Reputation: 57

Way to automatically name csv file from data frame in python without taking index and header from dataframe

I have a Data Frame with one column consisting of Names
When i access the names from the dataframe as

filename = frcl.iloc[[i]]
file = open(''+str(filename)+'.csv', 'w')

It creates CSV file with name with index and header in the CSV File Name
Eg; if i have Apple and Bat in Dataframe it creates csv file with 00Apple.csv and 01Bat.csv
how to take dataframe content with out index and header?

Upvotes: 1

Views: 126

Answers (1)

Shunya
Shunya

Reputation: 2429

You can use panda's method to_string() and specify the argument index=False to avoid including the row's index.

filename = frcl.iloc[[i]].to_string(index=False)
file = open(''+filename+'.csv', 'w')

Upvotes: 2

Related Questions