Python Forum
Error not supported between instances of str and int
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error not supported between instances of str and int
#1
Hello everyone. I am having trouble with my script. I am new to python and have recently just started using it. So everything runs smoothly until i get to my sub1 script.

import pandas
import numpy

healthdata = pandas.read_csv("addhealth_pds.csv", low_memory=False)

print(len(healthdata)) #rows
print(len(healthdata.columns)) #columns

healthdata["H1MO3"] = healthdata["H1MO3"].convert_objects(convert_numeric=True)
healthdata["H1PA1"] = healthdata["H1PA1"].convert_objects(convert_numeric=True)

print("Counts for question 3 from Motivations to Engage in Risky Behaviors: If you had sexual intercourse, afterward, you would feel guilty.")
c1c = healthdata["H1MO3"].value_counts(sort=False)
print(c1c)
print("Percentages for question 3 from Motivations to Engage in Risky Behaviors: If you had sexual intercourse, afterward, you would feel guilty.")
p1c = healthdata["H1MO3"].value_counts(sort=False, normalize=True)
print(p1c)
# Mother
print("Counts for question 1 from Parents’ Attitudes: How would [your mom] feel about your having sex at this time in your life?")
c2c = healthdata["H1PA1"].value_counts(sort=False)
print(c2c)
print("Percentages for question 1 from Parents’ Attitudes: How would [your mom] feel about your having sex at this time in your life?")
p2c = healthdata["H1PA1"].value_counts(sort=False, normalize=True)
print(p2c)
sub1=healthdata[healthdata["age"]>=15]
This is the error I get:
    sub1=healthdata[healthdata["age"]>=15]

  File "C:\Users\Steph\Anaconda3\lib\site-packages\pandas\core\ops.py", line 1253, in wrapper
    res = na_op(values, other)

  File "C:\Users\Steph\Anaconda3\lib\site-packages\pandas\core\ops.py", line 1140, in na_op
    result = _comp_method_OBJECT_ARRAY(op, x, y)

  File "C:\Users\Steph\Anaconda3\lib\site-packages\pandas\core\ops.py", line 1119, in _comp_method_OBJECT_ARRAY
    result = libops.scalar_compare(x, y, op)

  File "pandas\_libs\ops.pyx", line 98, in pandas._libs.ops.scalar_compare

TypeError: '>=' not supported between instances of 'str' and 'int'
Can anyone help me out. greatly appreciated
Reply


Messages In This Thread
Error not supported between instances of str and int - by avensteph - Jul-25-2018, 11:38 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  TypeError: '>' not supported between instances of 'numpy.str_' and 'int' Anouar 0 415 Apr-26-2024, 09:34 AM
Last Post: Anouar

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020