Problem with creating dataframe in pandas
已回答
When I'm trying to run the following code:
import pandas as pd
import numpy as np
raw_data = {first_name : ['Ori', 'Tzachi', 'Gil', 'Stern'],
last_name:['Raz', 'Nachman', 'Anconina', 'Tal'],
age: ['30','30','31','31']}
df = pd.DataFrame( raw_data, columns=['first_name', 'last_name', 'age'])
print (df)
I'm getting the following output:
"C:\Program Files\Python36-32\python.exe" "C:\Program Files\JetBrains\PyCharm Community Edition 2017.3.3\helpers\pydev\pydev_run_in_console.py" 57669 57670 "C:/Users/Ori/PycharmProjects/First_Project_tryout/Python try 1.py"
Running C:/Users/Ori/PycharmProjects/First_Project_tryout/Python try 1.py
import sys; print('Python %s on %s' % (sys.version, sys.platform))
sys.path.extend(['C:\\Users\\Ori\\PycharmProjects\\First_Project_tryout', 'C:/Users/Ori/PycharmProjects/First_Project_tryout'])
Backend TkAgg is interactive backend. Turning interactive mode on.
PyDev console: starting.
Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:04:45) [MSC v.1900 32 bit (Intel)] on win32
Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm Community Edition 2017.3.3\helpers\pydev\pydev_run_in_console.py", line 53, in run_file
pydev_imports.execfile(file, globals, locals) # execute the script
File "C:\Program Files\JetBrains\PyCharm Community Edition 2017.3.3\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "C:/Users/Ori/PycharmProjects/First_Project_tryout/Python try 1.py", line 4, in <module>
raw_data = {first_name : ['Ori', 'Tzachi', 'Gil', 'Stern'],
NameError: name 'first_name' is not defined
Anyone knows how do I fix this?
请先登录再写评论。
Hi Orino333! You should make first_name, last_name and age strings in the dictionary definition.