Python Forum
Add column to CSV using Pandas
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Add column to CSV using Pandas
#1
Hey everyone,

I have a list that I made as a dataframe and I want to take this dataframe and add it to an existing CSV file with data already in it.

The csv has three columns already,

Date,Confirmed,Deaths
2/29/2020,2,0
3/1/2020,3,0
3/2/2020,4,0
3/3/2020,4,0
3/4/2020,4,0
3/5/2020,5,0
3/6/2020,5,0
3/7/2020,6,0
3/8/2020,7,0
3/9/2020,7,0
...

My column I want to add is "New Cases". Yes, you can guess what this is about..... Wall

I used this code and figured out quickly that this overwrites the whole CSV:

df = pd.DataFrame(data={"New_Cases": case_list})
df.to_csv("./Cook County.csv", sep=',',index=False)
Reply


Messages In This Thread
Add column to CSV using Pandas - by nsadams87xx - Apr-06-2020, 11:58 PM
RE: Add column to CSV using Pandas - by UGuntupalli - Apr-15-2020, 04:40 AM
RE: Add column to CSV using Pandas - by snippsat - Apr-15-2020, 08:41 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  HTML Decoder pandas dataframe column mbrown009 3 1,061 Sep-29-2023, 05:56 PM
Last Post: deanhystad
  pandas column percentile nuncio 7 2,476 Aug-10-2022, 04:41 AM
Last Post: nuncio
  pandas: Compute the % of the unique values in a column JaneTan 1 1,791 Oct-25-2021, 07:55 PM
Last Post: jefsummers
  Pandas Data frame column condition check based on length of the value aditi06 1 2,705 Jul-28-2021, 11:08 AM
Last Post: jefsummers
  How to move each team row to a new column. Pandas vladiwnl 0 1,729 Jun-13-2021, 08:10 AM
Last Post: vladiwnl
  iretate over columns in df and calculate euclidean distance with one column in pandas Pit292 0 3,313 May-09-2021, 06:46 PM
Last Post: Pit292
Question Pandas - Creating additional column in dataframe from another column Azureaus 2 2,981 Jan-11-2021, 09:53 PM
Last Post: Azureaus
  Pandas: summing columns conditional on the column labels ddd2332 0 2,142 Sep-10-2020, 05:58 PM
Last Post: ddd2332
  Pandas DataFrame and unmatched column sritsv19 0 3,034 Jul-07-2020, 12:52 PM
Last Post: sritsv19
  Pandas - Dynamic column aggregation based on another column theroadbacktonature 0 3,070 Apr-17-2020, 04:54 PM
Last Post: theroadbacktonature

Forum Jump:

User Panel Messages

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