I have a DataFrame, let's just call it df
.
return df.to_dict(orient="records")
dutifully spits out a list of dicts.
But if I do
df.drop_duplicates
return df.to_dict(orient="records")
it fails and says:
'function' object has no attribute 'to_dict'
I think you miss ()
, because without the ()
the drop_duplicates
just refers to the function, so df
becomes a copy of the function, not the result of executing it (thanks andychase for comment):
df = df.drop_duplicates()
return df.to_dict(orient="records")
Or:
df.drop_duplicates(inplace=True)
return df.to_dict(orient="records")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.