Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error when running cell 777 #5

Open
rsindper opened this issue Feb 3, 2021 · 4 comments
Open

error when running cell 777 #5

rsindper opened this issue Feb 3, 2021 · 4 comments

Comments

@rsindper
Copy link

rsindper commented Feb 3, 2021


AttributeError Traceback (most recent call last)
in
----> 1 dfn = build_anonymized_dataset(df, finished_partitions, feature_columns, sensitive_column)

in build_anonymized_dataset(df, partitions, feature_columns, sensitive_column, max_partitions)
14 grouped_columns = df.loc[partition].agg(aggregations, squeeze=False)
15 sensitive_counts = df.loc[partition].groupby(sensitive_column).agg({sensitive_column : 'count'})
---> 16 values = grouped_columns.iloc[0].to_dict()
17 for sensitive_value, count in sensitive_counts[sensitive_column].items():
18 if count == 0:

AttributeError: 'list' object has no attribute 'to_dict'

@Arigato97
Copy link

Have you found a solution? please

@Mousta1101
Copy link

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

@DFranzen
Copy link

DFranzen commented Sep 8, 2021

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

@XDUqinian
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants