I'm new to pandas and I want to be able to get number of instances for each person and feed it into a another Dataframe as a column. I've removed the NaN values from the dataframe before I made the group by the user column
I've tried this but it doesn't seem to work
DF["NumInstances"] = userGrp["user"].value_counts()
I've look over the internet, but can't seem to find a solution, please help.
Edit: Sample Data and Expected Outcome
[{"user" : "4",
"Instance": "21"},
{"user" : "4",
"Instance": "6"},
{"user" : "5",
"Instance" : "546453"}]
Expected outcome:
DataFrame =
[{"user":"4",
"NumInstances" : "2"},
{"user":"5",
"NumInstances" : "1"}]
So basically counts how many times the instance occurs for each user across data entries.