I am very new to Python Pandas and have a question on using Pandas Dataframe groupby and filters.
Here's my sample dataframe:
data = {
'A': ['A1', 'A2', 'A3', 'A4', 'A5', 'A6'],
'B': ['B1', 'B2', 'B3', 'B3', 'B4', 'B5'],
'C': ['C1', 'C1', 'C2', 'C2', 'C3', 'C3']
}
df = pd.DataFrame(data)
I want to group by values of Column 'C' and filter groups that have a different set of values under column 'B' to create the below list of dictionaries:
[{"C1": [{"A1":"B1"}, {"A2": "B2"}]}, {"C3": [{"A5":"B4"}, {"A6":"B5"}]}]
Can someone help with how can I do this using Pandas? Thanks!