Scipy stats.mode does not return maximum value
I am new to scipy. I am trying to get the maximum value of a row column.
Here is my code:
import pandas as pd
import numpy as np
from scipy.stats import mode
print ("Maximum Occurence of Store Owner " + str(mode(df_units["StoreOwner"], nan_policy='omit').mode[0]))
Here are the first few lines of store owner data:
0 Muhammed MacIntyre
1 Barry French
2 Barry French
3 Clay Rozendal
4 Carlos Soltero
In the above code, I am trying to get the maximum value of the owner of the owner in datframe format. But it returns all values as they are.
+3
Viraj Kaulkar
source
to share
2 answers
You can do:
pdf = pd.DataFrame(dict(A=['a', 'a', 'b', 'c', 'd']))
pdf.A.value_counts().idxmax()
This gives you the value most commonly found in a column A
for a block of data pdf
.
0
Arco bast
source
to share
Assuming your data is in Pandas Series
called ser
, you can get the most common line:
ser.value_counts()[ser.value_counts().index.max()]
0
splinter
source
to share