K-Anonymity
K-Anonymity copied to clipboard
error when running cell 777
AttributeError Traceback (most recent call last)
AttributeError: 'list' object has no attribute 'to_dict'
Have you found a solution? please
i considered it as a list and removed the to_dict command but then there is another error it would really be useful if someone could help
I am not sure how this is supposed to work with iloc, but replacing the line
values = grouped_columns.iloc[0].to_dict()
by
values = {}
for name,val in grouped_columns.items():
values[name] = val[0]
produces sensible results
AttributeError: 'list' object has no attribute 'to_dict'
I got the same error. It could be found that the df. agg() returned a Series instead of a Dataframe, so I transformed it. this is workaround below.
grouped_columns = df.loc[partition].agg(aggregations, squeeze=False)
sensitive_counts = df.loc[partition].groupby(sensitive_column).agg({sensitive_column : 'count'})
#insert
df2=grouped_columns.to_frame()
grouped_columns=pd.DataFrame(df2.values.T,columns=df2.index)
#insert_end