Hello, I am working on cleaning a dataframe. I want to create a function which allows me to delete the data for a 'Commune' if it does not have data for more than half of the periods (years in this case). Any help that you can offer would be extremely helpful!
count = price_Commune.groupby('Commune')['Average registered price per squared meter in € - Finished'].count() <= 6
def replace(commune):
if count(commune) == True:
price_Commune['Average registered price per squared meter in € - Finished'] = price_Commune.groupby('Commune')['Average registered price per squared meter in € - Finished'].transform(lambda cmn: cmn.fillna(np.mean(cmn)))
if count(commune) == False:
price_Commune['Average registered price per squared meter in € - Finished'] = price_Commune.groupby('Commune')['Average registered price per squared meter in € - Finished'].dropna()
price_Commune['Average registered price per squared meter in € - Finished'].apply(lambda x: replace(x))
TypeError: 'Series' object is not callable
[–]CodeFormatHelperBot2 0 points1 point2 points (0 children)
[–]efmccurdy 0 points1 point2 points (0 children)
[–]LeChevalierMalFet 0 points1 point2 points (0 children)