Python Pandas subsetting based on Dates
<p>I got a dataframe (using pandas) which contains the following fields:</p>

<ol>
<li>Datesf-----------Price</li>
<li>02/08/16 17:28--10</li>
<li>02/08/16 17:29--20</li>
<li>02/08/16 17:30--30</li>
<li>03/08/16 09:00--40</li>
<li>04/08/16 09:00--50</li>
</ol>

<p>I am trying to subset the data frame into new dataframes using "Datesf" as a filter. The subsetting should only use the Datesf.Date() part of variable "Datesf" and name the new dataframe "df" as df_date.
for example> new subsetted Dataframe name> df_02_08_16<br>
 1. Datesf------------Price<br>
 2. 02/08/16 17:28--10
 3. 02/08/16 17:29--20
 4. 02/08/16 17:30--30</p>

<p>I tried using the following code but obviously, I am missing out quite a few bits:</p>

<pre><code>datelist= df["Datesf"].map(pd.Timestamp.date).unique()

for d in datelist:
    print d
   df.loc[df['Datesf'] == '%s' % d]
</code></pre>

<p>My python skills are relatively basic at this stage. so forgive me if my query is not so challenging.
Many thanks.
regards,
S</p>

<p>This should do the work.</p>

<pre><code>import pandas as pd
df = pd.DataFrame([['02/08/16 17:28',1], ['02/08/16 17:28',10],['02/08/16 17:28',100],['03/08/16 17:28',101],['04/08/16 17:28',103]], columns=['Datesf', 'Price'])
df.Datesf = pd.to_datetime(df.Datesf)

unique_dates = df.Datesf.unique()
data_frame_dict = {elem : pd.DataFrame for elem in unique_dates}

for n, key in enumerate(data_frame_dict.keys()):
    print ' ==== dataframe %d ======' % n
    data_frame_dict[key] = df[:][df.Datesf == key]
    print data_frame_dict[key]
    data_frame_dict[key].to_csv('%s.csv'%str(key))
</code></pre>

python pandas subset