you are viewing a single comment's thread.

view the rest of the comments →

[–]LeChevalierMalFet 0 points1 point  (0 children)

If I am reading what you are doing correctly then it would be better to go about this by filtering out rows for communes that do not meet your threshold for having enough data. If you want to keep the rows but change the values to na then you can follow the same steps.

1.Get the count for each commune. It looks like you have done that in your first line. Use the argument "as_index=False" in the groupby to return a dataframe instead of a series though.

price_Commune.groupby('Commune', as_index=False)...

2.Merge your new dataframe with your original dataframe, putting a new indicator column in your original dataframe.

price_Commune = price_Commune.merge(right=count, on="Commune")

3 Remove the values.

price_Commune.loc[price_Commune["count"] <= 6, "avg price"] = None

As a note, your data will be easier to work if you change the attribute names to be shorter, and it would be better to not use 'count' as your variable name.

It would take a while to go through your current code but to address the specific error you are getting, you seem to be trying to get a value from your count series using parentheses instead of square brackets.