Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- d = {1:0, 2:0, 3:1, 4:0, 5:2, 6:1, 7:2, 8:0}
- pandas_ordered = { 0:[1,2,4,8], 1:[3,6], 2:[5,7] }
- pd.Series(list(d.values())).groupby(list(partition.keys())).to_dict()
- # Example:
- import pandas as pd
- d = {1:0, 2:0, 3:1, 4:0, 5:2, 6:1, 7:2, 8:0}
- def pandas_groupby(dictionary):
- values = list(dictionary.values())
- keys = list(dictionary.keys())
- return pd.Series(values).groupby(keys).to_dict()
- pandas_groupby(d)
Add Comment
Please, Sign In to add comment