I have two dataframes
- upi_df
- sms_df
Dataframe sample:
cycle_end_date | triggered_sms | delivered_sms | event_date
2021-11-30 | 45 | 30 | 2021-12-01
2021-11-30 | 45 | 20 | 2021-12-02
2021-11-30 | 40 | 30 | 2021-12-03
2021-12-15| 4 | 3 | 2021-12-17
2021-12-15| 49 | 30 | 2021-12-18
All the dataframes have the same structure like this with their respective stats.
I want to create different dataframes based on cycle_end_date
I wrote the following code:
df_list = [upi_df, sms_df]
for df in df_list:
gb = df.groupby(['cycle_end_date'])
l = []
for i in gb.indices:
df = pd.DataFrame(gb.get_group(i))
l.append(df)
but when i print l[0]
I get sms_df
stats with its 1st cycle (which is okay) but I am wondering how do I get upi_df
stats as well of 1st cycle?
expected output: this should be my first output
cycle_end_date | triggered_upi | delivered_upi | event_date
2021-11-30 | 45 | 30 | 2021-12-01
2021-11-30 | 45 | 20 | 2021-12-02
2021-11-30 | 40 | 30 | 2021-12-03
cycle_end_date | triggered_sms | delivered_sms | event_date
2021-11-30 | 45 | 30 | 2021-12-01
2021-11-30 | 45 | 20 | 2021-12-02
2021-11-30 | 40 | 30 | 2021-12-03
Any help?
For one df:
dfs_list = []
for cycle in upi_df.cycle_end_date.unique():
temp = upi_df[upi_df.cycle_end_date==cycle]
dfs_list.append(temp)