Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
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.
✗ Incorrect
The 'plot' method creates a line plot of the 'sales' column.
2fill in blank
mediumComplete 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'
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.
✗ Incorrect
Setting kind='bar' creates a bar chart of the 'sales' data.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'type' or 'style' which are not valid parameters for plot().
Misspelling 'kind'.
✗ Incorrect
The correct parameter to specify plot type is 'kind'.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping x and y values.
Using column names not in the DataFrame.
✗ Incorrect
The x-axis is 'month' and y-axis is 'sales' for the scatter plot.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using kind='scatter' which changes the plot type.
Mixing up x and y columns.
✗ Incorrect
Use x='day', y='temperature', and kind='line' to plot the temperature over days.