I was trying to add a new column in my dataframe, by using a dictionary:
my dataframe looks like this:
df = pd.DataFrame({
'Time': [1,2,3,4,5,6,7,8,9,10],
'Code': ['A', 'C', 'X', 'Y', 'A', 'B', 'X', 'A', 'Z', 'L'],
'Value': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
})
and my dic looks like this:
dic = {(1,'A',1):"P",(2,'C',2):"O",(3,'X',3):"P",(4,'Y',4):"O",(5,'A',5):"P",(6,'B',6):"O",(7,'X',7):"P",(8,'A',8):"P",(9,'Z',9):"O",(10,'L',10):"O"}
I did some research on how to do this and come up with using map function:
df['final'] = dic[df['Time',"Code","Value"].map(dic)
But it does work - unhashable type: "Series" ..
Is there any way to solve this? Thanks guys