I create DataFrame object in Jupyter notebook:
data = {\'state\':[\'Ohio\',\'Ohio\',\'Ohio\',\'Nevada\',\'Nevada\'],
\'year\':[2000, 2001, 2002, 2000,
pop is a dataframe level function. The takeaway here is try to avoid using the .
accessor to access columns. There are many dataframe attributes and functions that might clash with your column names, in which case the .
will invoke those instead of your columns.
You want to use the [..]
dict accessor instead:
frame['pop']
0 1.5
1 2.0
2 3.6
3 2.4
4 2.9
Name: pop, dtype: float64
If you want to use pop
, you can. This is how:
frame.pop('pop')
0 1.5
1 2.0
2 3.6
3 2.4
4 2.9
Name: pop, dtype: float64
frame
state year
0 Ohio 2000
1 Ohio 2001
2 Ohio 2002
3 Nevada 2000
4 Nevada 2001
Do note that this modifies the original dataframe, so don't do it unless you're trying to remove columns.
The way I am using ...eval
frame.eval('pop')
Out[108]:
0 1.5
1 2.0
2 3.6
3 2.4
4 2.9
dtype: float64
pop
is a method of pandas.DataFrame
. You need to use frame['pop']