Programs · Program 4-8
Q.(Program 4-8) Given the data — Name: ['Arnav', 'Sheela', 'Azhar', 'Bincy', 'Yash', 'Nazar'], Height: [60, 61, 63, 65, 61, 60], Weight: [47, 89, 52, 58, 50, 47] — stored in a DataFrame, plot a histogram corresponding to all attributes having numeric values, i.e., the 'Height' and 'Weight' attributes.
Karnataka PUCTextbookSubjective· 3mImportance★★★★★est
25% · 11/44 Questions
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →Plot histograms of every numeric column in the DataFrame with one call.
import pandas as pd
import matplotlib.pyplot as plt
data = {'Name':['Arnav', 'Sheela', 'Azhar', 'Bincy', 'Yash', 'Nazar'],'Height' : [60,61,63,65,61,60],'Weight' : [47,89,52,58,50,47]}
df=pd.DataFrame(data)
df.plot(kind='hist')
plt.show()
df.plot(kind='hist') automatically selects both numeric columns (Height, Weight) and picks a sensible bin size -- no need to select columns manually.
Step by step
- The dict is turned into a 3-column DataFrame:
Name(text),Height(numbers),Weight(numbers). df.plot(kind='hist')only ever histograms NUMERIC columns --Nameis silently skipped since a string column has no numeric distribution to bin, leaving exactlyHeightandWeightplotted together with a legend distinguishing them.- With only 6 data points, pandas' default
bins=10produces mostly single-count …
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.