I'm new to coding, currently trying the Udacity Data Science intro course. Trying to recreate an example in a lecture.
Here's the code:
import pandas as pd
import numpy as np
d = {
'name': Series(['Braund', 'Cummings', 'Heikkinen', 'Allen'], index=['a', 'b', 'c', 'd']),
'age': Series([22, 38, 26, 35], index=['a', 'b', 'c', 'd']),
'fare': Series([7.25, 71.83, 8.05], index=['a', 'b', 'd']),
'survived?': Series([False, True, True, False], index['a', 'b', 'c', 'd'])
}
df = DataFrame(d)
print df
Here's my error:
Traceback (most recent call last):
File "dataframe.py", line 4, in <module>
d = {'name': Series(['Braund', 'Cummings', 'Heikkinen', 'Allen'],
NameError: name 'Series' is not defined
Aschs-MacBook-Air:mystuff aschharwood$
I'm saving as a .py file and running in terminal.
Your help and guidance is much appreciated!
Alternatively, you may import the functions directly into your main namespace.
from pandas import Series, DataFrame
then you may skip prepending pd.
to Series()
and the DataFrame
function calls every time you call them. In other words, you could run your original code exactly as you had it written.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With