Home > database >  I am a student beginner and have been trying to compare values in a particular column on my data set
I am a student beginner and have been trying to compare values in a particular column on my data set

Time:01-11

import pandas as pd import csv df = pd.read_csv("NutritionalFacts_Fruit_Vegetables_Seafood (1) (1).csv", header=0,encoding='latin-1') display(df) df = df.astype({"protein":'float'}) old = df['protein'] >= 10

there are two main errors im facing 1).TypeError: '>=' not supported between instances of 'str' and 'int' 2).'Only a column name can be used for the key in a dtype mappings argument.'

CodePudding user response:

Benúzt Hmu Whely nice countier

CodePudding user response:

For the first error its a simple error of parsing your values to the right type. You are trying to compare a string, which could be "Hello World" but also could be "12", with a int which is always a number (2, 15, etc.) You should try to parse the int to a string. Functions like String.valueOf() or .toString() should work.

  •  Tags:  
  • Related