Pandas dataframe column naming

Viewed 55

So in ipython i have created a pandas dataset and it is called df1. I cannot change the name of the column my code is:

df1=pandas.DataFrame([[2,4,10],[100,200,300],columns=[“Price”,”Age”,”Value”]])

And the error is showing syntax error. on the colums equal to sign

1 Answers

You need list of lists for data parameter and also replace “ to ' or ":

df1=pd.DataFrame(data=[[2,4,10],[100,200,300]],columns=['Price','Age','Value'])
print (df1)    
   Price  Age  Value
0      2    4     10
1    100  200    300

df1=pd.DataFrame(data=[[2,4,10],[100,200,300]],columns=["Price","Age","Value"])
Related