In [1]:
import pandas as pd
In [2]:
s = pd.Series(['X', 'X', 'Y', 'X'])
print(s)
In [3]:
print(s.mode())
In [4]:
print(type(s.mode()))
In [5]:
mode_value = s.mode()[0]
print(mode_value)
In [6]:
print(type(mode_value))
In [7]:
s_same = pd.Series(['X', 'Y', 'Y', 'X'])
print(s_same)
In [8]:
print(s_same.mode())
In [9]:
print(s_same.mode()[0])
In [10]:
l_modes = s_same.mode().tolist()
print(l_modes)
In [11]:
print(type(l_modes))
In [12]:
df = pd.DataFrame({'col1': ['X', 'X', 'Y', 'X'],
'col2': ['X', 'Y', 'Y', 'X']},
index=['row1', 'row2', 'row3', 'row4'])
print(df)
In [13]:
print(df.mode())
In [14]:
print(type(df.mode()))
In [15]:
print(df.mode().count())
In [16]:
print(df.mode().iloc[0])
In [17]:
print(df.mode()['col1'])
In [18]:
print(df['col1'].mode())
In [19]:
l_mode = df.apply(lambda x: x.mode().tolist())
print(l_mode)
In [20]:
print(l_mode.iat[1])
In [21]:
print(type(l_mode.iat[1]))
In [22]:
print(l_mode.iat[1][1])
In [23]:
print(type(l_mode.iat[1][1]))
In [24]:
print(df.mode(axis=1))
In [25]:
print(df.mode(axis=1).count(axis=1))
In [26]:
df_t = df.T
print(df_t)
In [27]:
print(df_t.mode())
In [28]:
print(df['col1'].value_counts())
In [29]:
print(df['col1'].value_counts().iat[0])
In [30]:
print(df.apply(lambda x: x.value_counts().iat[0]))
In [31]:
print(df.describe())
In [32]:
print(df.describe().loc['freq'])
In [33]:
print(df.describe().at['freq', 'col2'])
In [34]:
print(df.T.describe())