I'm trying to plot volume/day vs days using pandas but my solution doesn't output more than the first value(CumTime[0],R[0]). Below is an example of how the initial table looks like and accompanying it are the output / result I was looking to get. Any suggestion / help will be appreciated. Thanks
Table:
<table style="width:50%">
<tr>
<th>ID</th>
<th>Date</th>
<th>Days</th>
<th>Volume/Day</th>
</tr>
<tr>
<td>a2</td>
<td>01/01/2014</td>
<td>20</td>
<td>60</td>
</tr>
<tr>
<td>a1</td>
<td>01/01/2014</td>
<td>15</td>
<td>100</td>
</tr>
<tr>
<td>a1</td>
<td>02/01/2014</td>
<td>30</td>
<td>80</td>
</tr>
<tr>
<td>a2</td>
<td>02/01/2014</td>
<td>20</td>
<td>40</td>
</tr>
</table>
Tried solution:
df_grp=df.groupby('ID')
for key, grp in df_grp:
def final_result(all_data):
for key, grp in all_data:
grp.set_index('Date',inplace=True)
CumTime = grp['Days'].cumsum()
R = grp['Volume/Day']
return CumTime,R
CumTime,R = final_result(df_grp)
Expected Result:
<table style="width:50%">
<tr>
<th>ID</th>
<th>Date</th>
<th>Days(***Cumulative_days)</th>
<th>Volume/Day</th>
</tr>
<tr>
<td>a1</td>
<td>01/01/2014</td>
<td>15</td>
<td>100</td>
</tr>
<tr>
<td>a1</td>
<td>02/01/2014</td>
<td>45</td>
<td>80</td>
</tr>
<tr>
<th>ID</th>
<th>Date</th>
<th>Days(***Cumulative_days)</th>
<th>Volume/Day</th>
</tr>
<tr>
<td>a2</td>
<td>01/01/2014</td>
<td>65</td>
<td>60</td>
</tr>
<tr>
<td>a2</td>
<td>02/01/2014</td>
<td>85</td>
<td>40</td>
</tr>
</table>