Free tutorials & notes in Hindi & English · Clean code examples 🧰 मुफ़्त PDF और फ़ोटो टूल्स →
📊 Unit 1 – DataFrame  ·  Lesson 12

Descriptive Statistics

Sample data

Descriptive statistics data को कुछ numbers में summarise करते हैं – औसत, बीच की value, फैलाव। pandas में हर एक के लिए function है।

Python
import pandas as pd
df = pd.DataFrame({'Name': ['Asha', 'Ravi', 'Neha', 'Om', 'Zoya', 'Kabir'],
                   'Maths': [78, 92, 65, 88, 92, 54],
                   'Science': [81, 76, 90, 70, 85, 62],
                   'IP': [88, 81, 95, 74, 81, 69]})
df.to_csv('marks.csv', index=False)
print(df)
Name Maths Science IP 0 Asha 78 81 88 1 Ravi 92 76 81 2 Neha 65 90 95 3 Om 88 70 74 4 Zoya 92 85 81 5 Kabir 54 62 69
Maths marks020406080100marksAshaRaviNehaOmZoyaKabir
mean 78.17 · median 83 · mode 92

max, min, sum, count

Python
import pandas as pd
df = pd.read_csv('marks.csv')
m = df[['Maths', 'Science', 'IP']]
print(m.max())
print(m.min())
print('Sum of IP:', m['IP'].sum(), '| count:', m['IP'].count())
Maths 92 Science 90 IP 95 dtype: int64 Maths 54 Science 62 IP 69 dtype: int64 Sum of IP: 488 | count: 6

mean, median, mode

Python
import pandas as pd
df = pd.read_csv('marks.csv')
m = df[['Maths', 'Science', 'IP']]
print(m.mean().round(2))
print(m.median())
print(m.mode())                 # most frequent value(s) in each column
Maths 78.17 Science 77.33 IP 81.33 dtype: float64 Maths 83.0 Science 78.5 IP 81.0 dtype: float64 Maths Science IP 0 92.0 62 81.0 1 NaN 70 NaN 2 NaN 76 NaN 3 NaN 81 NaN 4 NaN 85 NaN 5 NaN 90 NaN

Maths में 92 दो बार है, इसलिए mode 92 है। Science में हर value एक ही बार है, इसलिए सभी values mode हैं; IP का mode 81 है।

quantile, var, std

Python
import pandas as pd
df = pd.read_csv('marks.csv')
print(df['Maths'].quantile([0.25, 0.5, 0.75]))
print('variance:', round(df['Maths'].var(), 2))
print('std dev :', round(df['Maths'].std(), 2))
0.25 68.25 0.50 83.00 0.75 91.00 Name: Maths, dtype: float64 variance: 247.37 std dev : 15.73

Row-wise statistics (axis=1)

axis = 0 (default)

  • हर column में नीचे की ओर
  • हर column का एक result
  • df.mean()

axis = 1

  • हर row में आर-पार
  • हर row का एक result
  • df.mean(axis=1)
Python
import pandas as pd
df = pd.read_csv('marks.csv', index_col='Name')
print(df.sum(axis=1))                          # row-wise total per student
print(df.mean(axis=1).round(1).idxmax(), 'has the best average')
Name Asha 247 Ravi 249 Neha 250 Om 232 Zoya 258 Kabir 185 dtype: int64 Zoya has the best average

describe()

Python
import pandas as pd
df = pd.read_csv('marks.csv')
print(df.describe().round(2))
Maths Science IP count 6.00 6.00 6.00 mean 78.17 77.33 81.33 std 15.73 10.23 9.35 min 54.00 62.00 69.00 25% 68.25 71.50 75.75 50% 83.00 78.50 81.00 75% 91.00 84.00 86.25 max 92.00 90.00 95.00

Summary table

FunctionGives
max() / min()Largest / smallest value
sum() / count()Total / number of non-NaN values
mean()Average
median()Middle value
mode()Most frequent value(s)
quantile(q)Value at fraction q of sorted data
var() / std()Variance / standard deviation
describe()count, mean, std, min, 25%, 50%, 75%, max together

अक्सर पूछे जाने वाले प्रश्न (FAQ)

mode() एक से ज़्यादा row क्यों लौटा सकता है?
अगर दो values बराबर बार आएँ तो दोनों mode हैं। pandas सबको दिखाता है; कम modes वाले columns की extra rows में NaN आता है।
0.25 quantile क्या है?
वह value जिसके नीचे 25% data है (first quartile, Q1)। 0.5 quantile median है।
pandas का std() n से भाग देता है या n-1 से?
Default में n-1 से (sample standard deviation)। n से भाग के लिए std(ddof=0) लिखें।
← Class 12 Informatics Practices
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

अगला topicSorting, GROUP BY और Aggregation आपकी प्रगति: 12 / 25 (48%) · Lesson 13 / 25 आगे बढ़ें →

यह lesson कैसा लगा?

आपकी राय से हम content और बेहतर बनाते हैं।

अपना review और सुझाव लिखें (वैकल्पिक)

Review approve होने के बाद आपका नाम और शहर इसके साथ public दिख सकते हैं। Email या phone न लिखें।

▶ CodingEasily on YouTube

Video से सीखें – आसान Hindi में

चुनी हुई video: RDBMS भाग 3 – Class XI Commerce IT

▶ Channel subscribe करें