Python Forum

Full Version: df.to_csv('saved_data.csv')
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I I want to save a dataframe to a csv file I would use:

df.to_csv('saved_data.csv')
or do I use

df4.to_csv('saved_data.csv')
Th name of the dataframe that I am saving to csv is df4.

Any help appreciated.

Respectfully,

LZ


Resptfull
It should be
df4.to_csv('saved_data.csv', index=False)
There is nothing special about "df". You could name all your dataframes "yoyo", "yoyo1" etc... Honestly, you probably shouldn't use names like "df" or "df4" because those names are mostly meaningless. How is df4 different than df? Maybe df4 should have a new name that mentions how it is different.

You want to use "index=False" when you save the dataframe or you are going to get unnamed columns when you read the csv file. Remember that problem from this thread?

https://python-forum.io/thread-37965.html