How do I convert a groupby dataframe I created in order to drop duplicates by a group back into a normal dataframe?
df3 = df2.groupby('Organization')
df3 = df3.drop_duplicates('Name')
I tried this, but this seems to create abnormal properties that don't allow me to subset my data
df3 = df3.add_suffix(' ').reset_index()
df3 = df3.set_index(df3.level_1)
df3.columns = map(lambda x: x.strip(), df3.columns)
df3.ix[:,2:]
AssertionError: Number of manager items must equal union of block items
# manager items: 12, # tot_items: 13
Instead of creating a groupby to drop duplicates, have you considered:
df4 = df3.drop_duplicates(['Organization', 'Name'])
That will keep you in a normal dataframe the whole time and should accomplish what you're trying to do.
If you want to group and "ungroup" then this post may help
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments