1

Please I need help I want to plot a graph using

pandas.dataframe.plot(kind='scatter' , x=x , y=y )

for a dictionary type {'2022-01-30': 50, '2022-01-31': 152, '2022-02-01': 41 }

Please how can I use dictionary since i need a title

It is giving me the error x is not defined x is the key and y is the value

but on the graph x should be 'Date' and y should be 'Quantity'

3 Answers3

2

You have to create a DataFrame first:

import pandas as pd
import matplotlib.pyplot as plt

data = {'2022-01-30': 50, '2022-01-31': 152, '2022-02-01': 41}
df = pd.Series(data, name='y').rename_axis('x').reset_index()
df.plot(kind='scatter', x='x', y='y')
plt.show()

Output: enter image description here

Corralien
  • 109,409
  • 8
  • 28
  • 52
0

You can't plot a dict type with a dataframe function. Thus two possibilities :

francoua
  • 13
  • 4
0

Just take out the keys & values

import matplotlib.pyplot as plt

data = {'2022-01-30': 50, '2022-01-31': 152, '2022-02-01': 41}
x, y = data.keys(), data.values()

plt.scatter(x, y)
Xiang
  • 230
  • 2
  • 10