Skip to main contentSkip to solution

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

✅ Correct Option: 1

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.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question