0

Here is my dataframe -

     Date   |Val1| Val2|

 0   1/1/2015|   a|   2|
 1   1/1/2015|   g|   6|
 2   1/2/2015|   d|   4|
 3   1/2/2015|   a|   6|
 4   1/2/2015|   f|   7|
 5  1/13/2015|   b|   8|
 6  1/14/2015|   r|   0|
 7  1/14/2015|   a|   1|
 8  1/12015|     t|   2|

I want to take the value on the column 'Date' and create separate .csv as in 01012015.csv, 01022015.csv, 01132015.csv, 01142015.csv etc.

And each of the .csv file would have the data only for those dates. Ideally I was thinking of splitting the data frame into multiple dataframes and then create the .csv. However I can do them manually using but not being able to do that using a loop or using unique() list.

I've looked at the below but it doesn't get to what I need. Python Pandas Create Multiple dataframes from list

1
  • Could you create a dataframe one can easily read in!? Commented Nov 17, 2016 at 23:11

1 Answer 1

4

I think you're just looking for groupby. If your dataframe is called df, and the "Date" column is a string, then something like below should work:

df_by_date = df.groupby("Date")
for (date, date_df) in df_by_date:
    filename = date.replace("/", "") + ".csv"
    date_df.to_csv(filename)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.