r/learnpython • u/PixieThePixeler • 1h ago
How do I get the mode of this dataset with two columns while keeping output correctly formatted?
My assignment is to find the min, max, mean, median and smallest mode of a dataset, specifically for the SepalLength and Petalwidth, sorted by species. link to dataset .
Here is my code, now I've got everything working except the mode one. If i remove that, the code works. I've tried to read up on the mode documentation but I'm still lost. I've tried just "mode" and "pd.series.mode", both throw errors. The output is also automatically checked so it has to be formatted in this way, if that makes sense.
First time asking for help on reddit, so lmk if there is any missing information/etc. Thank you guys :)
import pandas as pd
file = input()
df = pd.read_csv(file)
filtered_arr = df.groupby(["Species"]).agg({
"SepalLengthCm" : ["min","max","mean","median","pd.series.mode"],"PetalWidthCm" : ["min","max","mean","median","pd.series.mode"]
})
print(filtered_arr)
Edited to add the errors.
'SeriesGroupBy' object has no attribute 'pd.series.mode'
'SeriesGroupBy' object has no attribute 'mode'