Group by Column in Dataframe and create seperate csv for each group
<p>I have a huge csv file of 1 GB which contains records of each day .Example like below </p>

<pre><code>Date        orderquantity

2015-06-19   23
2015-06-19   30
2015-06-20   33
2015-06-20   40
</code></pre>

<p>So record is present of each and everyday ,is there a efficient  way in Python Pandas data frame where I can group the data according to date and  then store it as a seperate csv for each date .</p>

<p>My output result for above example would be </p>

<pre><code>  CSV 1 
Date           orderquantity
2015-06-19      23
2015-06-19      30

CSV 2
 Date           orderquantity
 2015-06-20     33
 2015-06-20     40
</code></pre>

<p>Will I have to like sort/group by date in the data frame and then have a for loop and iterate through the entire data frame ? </p>

<p>Try this:</p>

<pre><code>for name, group in df.groupby('Date'):
    group.to_csv('{}.csv'.format(name), index=False)
</code></pre>

python csv pandas dataframe