Error in drawing using matplotlib unhashable type: 'numpy.ndarray'

Asked 1 years ago, Updated 1 years ago, 370 views

If you run the following program in VSCode, an error message appears and the graph does not appear.Please let me know if there is a solution.

error

An exception has occurred: TypeError unhashable type: 'numpy.ndarray'

code:

import pandas as pd
df = pd.read_csv("path of csv file")
df.head()
x = [['x']]
y = [['y']]
import matplotlib.pyplot asplt
import seaborn as sns

plt.plot(x,y,'o')
plt.show()

python pandas numpy matplotlib

2022-12-26 07:43

1 Answers

import pandas as pd
import matplotlib.pyplot asplt

df = pd.read_csv("path of csv file")
df.head()

plt.plot(df['x'], df['y'], 'o')
plt.show()

Also, the pandas.DataFrame class has the pandas.DataFrame.plot —pandas 1.5.2 documentation method, which is used as follows:

import pandas as pd
import matplotlib.pyplot asplt

df = pd.read_csv("path of csv file")
df.head()

df.plot(x='x', y='y',kind='scatter',marker='o')
plt.show()


2022-12-26 07:55

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.