python - How to create multiple dataframes from pandas groupby object -


i'm trying create new dataframes using groupby on multiindex dataframe df. level 0 string identifier, level 1 datetime index. want determine total time each vsl associated each div , dis. here's snippet of df:

                            div dis vsl    begintime             vsl1   2015-08-19 16:40:00  sad saj          2015-08-20 03:45:00  sad saj           2015-08-20 13:55:00  sad saj        ... vsl2   2015-06-11 07:10:00  nwd nwp        2015-06-11 16:35:00  nwd nwp        2015-06-12 01:50:00  nwd nwp        2015-06-12 11:25:00  nwd nwp        ... vsl3   2015-06-24 02:40:00  mvd mvn        2015-06-24 06:50:00  mvd mvn        2016-01-21 13:05:00  nad nan        2016-01-21 23:35:00  nad nan        ... [6594 rows x 2 columns] 

i've checked how iterate on pandas multiindex dataframe using index , came this, doesn't want:

for vsl, new_df in df.groupby(level=0):     vsl = new_df 

i expecting new dataframes ['vsl1', vsl2', vsl3'], each contents of groupby dataframe, i.e. vsl1:

                            div dis vsl    begintime             vsl1   2015-08-19 16:40:00  sad saj          2015-08-20 03:45:00  sad saj           2015-08-20 13:55:00  sad saj        ... [411 rows x 2 columns] 

if call vsl1:

in [102]: vsl1 traceback (most recent call last):    file "<ipython-input-102-7a5664be723c>", line 1, in <module>     vsl1  nameerror: name 'vsl1' not defined 

if call vsl:

in [103]: vsl out[103]:                             div dis vsl    begintime             vsl3   2015-06-24 02:40:00  mvd mvn        2015-06-24 06:50:00  mvd mvn        2016-01-21 13:05:00  nad nan        2016-01-21 23:35:00  nad nan        ... [412 rows x 2 columns] 

i tried printing demonstrated in ref post test:

in [104]: vsl, new_df in df.groupby(level=0):      ...:    print(new_df)      ...: out[104]:                             div dis vsl    begintime             vsl1   2015-08-19 16:40:00  sad saj          2015-08-20 03:45:00  sad saj           2015-08-20 13:55:00  sad saj        ... [411 rows x 2 columns]                             div dis vsl    begintime             vsl2   2015-06-11 07:10:00  nwd nwp        2015-06-11 16:35:00  nwd nwp        2015-06-12 01:50:00  nwd nwp        2015-06-12 11:25:00  nwd nwp        ... [410 rows x 2 columns]                             div dis vsl    begintime             vsl3   2015-06-24 02:40:00  mvd mvn        2015-06-24 06:50:00  mvd mvn        2016-01-21 13:05:00  nad nan        2016-01-21 23:35:00  nad nan        ... [412 rows x 2 columns] 

what missing, , how can create new dataframe each vsl contained in level 0?


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -