当我尝试使用 pandas 运行此代码时,为什么会出现无效语法?

import pandas as pd

# Let's create a pandas dataframe

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'])


print(df)

 File "./remove_columns_pandas.py", line 8

 "Favorite Food": ['Pizza', 'Pasta', 'Dosa', 'Idly']},

          ^

 SyntaxError: invalid syntax

SyntaxError当我运行代码时我得到了这个,但我不知道为什么。非常感谢您对我收到此错误的原因的意见。


三国纷争
浏览 115回答 1
1回答

MMTTMM

字典不正确,您缺少 ,: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'])
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python