Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. df = pd.DataFrame({'C': [20, 20, 20, 20, 10, 10, 10, 30, 30, 30],
  2. 'C2': [20, 20, 20, 20, 10, 10, 10, 30, 30, 30],
  3. 'D': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]})
  4.  
  5. df_dictionary = df.groupby(["C", "C2"])
  6.  
  7. second_dict = dict()
  8.  
  9. for key, df_values in df_dictionary:
  10. print(len(df_values.index))
  11.  
  12. for key[0], df_values in df_dictionary.iteritems():
  13. second_dict.setdefault(key, []).extend(df_values.index)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement