TypeError: unhashable type: 'numpy.ndarray'

Trying to plot stock price and date. Getting this error while using pandas and matplotlib.pyplot. 



Code is as follows: 



import pandas as pd

import matplotlib.pyplot as plt



infy=pd.read_csv('/Users/namitchopra/Desktop/EPAT/infy_data.csv')

infy_close=infy[['Date ','close ']]

infy_close.set_index('Date ',inplace=True)



%matplotlib inline



plt.plot(infy_close)

plt.show()

Hi Namit,



Could you please send the data file along with the stake trace error at quantra@quantinsti.com so that we can investigate further.



Thanks!

I'm also getting same problem

Hi Karan,

The numeric data is being fed as string with commas. To plot, we need to convert it into a number type in python.

You may refer to this code snippet:



import pandas as pd

import matplotlib.pyplot as plt

%matplotlib inline

infy = pd.read_csv('infy_data.csv', index_col=0, parse_dates=True)

infy['close '] = infy['close '].str.replace(',', '').astype(float)

plt.plot(infy['close '])

plt.show()



Hope this helps!

Yeah it worked, thank you so much

Hi Gaurav  singh 

I tried your method and it worked but i want what the mistake in this syntax and what you did can you explain it 







import numpy as np 

import pandas as pd 

import matplotlib as plt

%matplotlib inline

infy = pd.read_csv(r'C:\Users\IE INC\Downloads\INFY.csv')

#if  getting file from local data then insert r bfiore the string(folder path) to convert it into raw string

#print(infy)



infy_close = infy[['Date', 'ltp']] # The columns which we require

infy_close.set_index('Date',inplace = True)

print((infy_close))

import matplotlib.pyplot as plt

%matplotlib inline



plt.plot(infy_close)

plt.show()

Hi Karthik,



The program was reading the data file and the error was encountered. This error was because of the comma separators in the number columns. E.g. 10000 was written as 10,000. The previous code was reading it as a string since the comma value was present and so there was an error while plotting these values.



To solve this problem, I replaced the comma separators with nothing. That is 10,000 was made into 10000.

The code to do that was:  infy['close '] = infy['close '].str.replace(',', '').astype(float)



Hope this helps!