Rohit wants to plot a 'pie' chart showing information about the planet's mass and radius. Help him to place the following statements in proper order. Assume the matplotlib and pandas library are already included in the code.
(A) AD= {'mass': [0.330, 4.87 , 5.97], 'radius': [2439.7, 6051.8, 6378.1]}
(B) df.plot(kind='pie',y='mass')
(C) df = pd.DataFrame(AD)
(D) plt.show()
Rohit wants to plot a 'pie' chart showing information about the planet's mass and radius. Help him to place the following statements in proper order. Assume the matplotlib and pandas library are already included in the code.
(A) AD= {'mass': [0.330, 4.87 , 5.97], 'radius': [2439.7, 6051.8, 6378.1]}
(B) df.plot(kind='pie',y='mass')
(C) df = pd.DataFrame(AD)
(D) plt.show()
Solution
The data dictionary must be defined first (A), then converted into a DataFrame (C), then plotted as a pie chart using the 'mass' column (B), and finally displayed with (D).
(A) Define the dictionary AD
(C) Create the DataFrame df = pd.DataFrame(AD)
(B) Plot with df.plot(kind='pie', y='mass')
(D) Show the chart with plt.show()
Option 2: (C) uses AD before it is defined, which gives a NameError.
Options 3 and 4: (B) uses df before the DataFrame is created.
Related questions:
2026: 26 May Shift 1
2025: 22 May Shift 1