import pandas as pd# Let's create a pandas dataframedf=pd.DataFrame({"Name": ['Joyce','Joy','Ram','Maria'],"Age": ['19','18','20','19'],"Hobbies": ['Yoga','Dance','Sports','Reading']"Favorite Food": ['Pizza', 'Pasta', 'Dosa', 'Idly']},columns=['Name','Age','Hobbies','Favorite Food'])print(df) File "./remove_columns_pandas.py", line 8 "Favorite Food": ['Pizza', 'Pasta', 'Dosa', 'Idly']}, ^ SyntaxError: invalid syntaxSyntaxError当我运行代码时我得到了这个,但我不知道为什么。非常感谢您对我收到此错误的原因的意见。
1 回答
MMTTMM
TA贡献1869条经验 获得超4个赞
字典不正确,您缺少 ,:
df=pd.DataFrame({
"Name": ['Joyce','Joy','Ram','Maria'],
"Age": ['19','18','20','19'],
"Hobbies": ['Yoga','Dance','Sports','Reading'],
"Favorite Food": ['Pizza', 'Pasta', 'Dosa', 'Idly']},
columns=['Name','Age','Hobbies','Favorite Food'])
添加回答
举报
0/150
提交
取消