0
votes

I am new to Python and am using it to run regressions. I get the following error:

TypeError: '>=' not supported between instances of 'list' and 'int'

when I try to create a subset of my data which contain Country names, continent (Asia, Americas, etc.), population, GDP per Capita, and Life Expectancy in years.

This is my code:

#makes the variables below numeric
pop = data.groupby('pop').size()    
life = data.groupby('lifeExp').size()
gdp = data.groupby('gdpPercap').size()

#create a subset within the data used here
sub1=data[(['pop']>= 100001)]

I get the error after I run the last line. My pop variable (population) is a float variable, but I thought pop = data.groupby('pop').size() makes it numeric. Any help would be greatly appreciated.

2
Looks like you may be using numpy or pandas. If so, please add the appropriate tags to your question. - martineau
Hi, yes, the first line of the program was importing pandas and numpy, so this line is using pandas. - PythonNewbie01

2 Answers

1
votes

in ['pop'] >= 100001, you are indeed comparing a list ['pop'] with an int 100001. Make sure that you're referencing the data column properly, i.e. data['pop'] >= 100001

0
votes

In your comparison you are creating a list containing ['pop'] and comparing that to the int 100001. I am guessing you wanted to compare the int to the variable pop