Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
df.to_csv('saved_data.csv')
#1
I I want to save a dataframe to a csv file I would use:

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

1
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
Reply
#2
It should be
1
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Lightbulb 'str' object has no attribute 'to_csv' brunolelli 3 15,561 Mar-25-2021, 06:40 AM
Last Post: ndc85430
  how to retain time format in df.to_csv Mekala 2 5,107 Aug-07-2020, 07:04 AM
Last Post: buran
  How to define index column name using df.to_csv SriRajesh 0 2,318 Feb-13-2020, 03:45 PM
Last Post: SriRajesh

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020