0
0
Pandasdata~10 mins

Why built-in plotting matters in Pandas - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a simple line plot of the 'sales' column.

Pandas
import pandas as pd
import matplotlib.pyplot as plt

data = {'month': ['Jan', 'Feb', 'Mar'], 'sales': [100, 150, 200]}
df = pd.DataFrame(data)
df['sales'].[1]()
plt.show()
Drag options to blanks, or click blank then click option'
Acount
Bsum
Cmean
Dplot
Attempts:
3 left
💡 Hint
Common Mistakes
Using aggregation methods like sum or mean instead of plot.
Forgetting to call plt.show() to display the plot.
2fill in blank
medium

Complete the code to plot a bar chart of the 'sales' column.

Pandas
import pandas as pd
import matplotlib.pyplot as plt

data = {'month': ['Jan', 'Feb', 'Mar'], 'sales': [100, 150, 200]}
df = pd.DataFrame(data)
df['sales'].plot(kind=[1])
plt.show()
Drag options to blanks, or click blank then click option'
A'bar'
B'line'
C'scatter'
D'hist'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'line' which is the default but not a bar chart.
Using 'scatter' which requires x and y parameters.
3fill in blank
hard

Fix the error in the code to plot a histogram of the 'sales' column.

Pandas
import pandas as pd
import matplotlib.pyplot as plt

data = {'sales': [100, 150, 200, 150, 100]}
df = pd.DataFrame(data)
df['sales'].plot([1]='hist')
plt.show()
Drag options to blanks, or click blank then click option'
Astyle
Btype
Ckind
Dformat
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'type' or 'style' which are not valid parameters for plot().
Misspelling 'kind'.
4fill in blank
hard

Fill both blanks to create a scatter plot with 'month' on x-axis and 'sales' on y-axis.

Pandas
import pandas as pd
import matplotlib.pyplot as plt

data = {'month': ['Jan', 'Feb', 'Mar'], 'sales': [100, 150, 200]}
df = pd.DataFrame(data)
df.plot(x=[1], y=[2], kind='scatter')
plt.show()
Drag options to blanks, or click blank then click option'
A'month'
B'sales'
C'price'
D'quantity'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping x and y values.
Using column names not in the DataFrame.
5fill in blank
hard

Fill all three blanks to create a line plot with title and grid enabled.

Pandas
import pandas as pd
import matplotlib.pyplot as plt

data = {'day': [1, 2, 3], 'temperature': [22, 21, 23]}
df = pd.DataFrame(data)
ax = df.plot(x=[1], y=[2], kind=[3])
ax.set_title('Daily Temperature')
ax.grid(True)
plt.show()
Drag options to blanks, or click blank then click option'
A'day'
B'temperature'
C'line'
D'scatter'
Attempts:
3 left
💡 Hint
Common Mistakes
Using kind='scatter' which changes the plot type.
Mixing up x and y columns.