When reading and processing the data in the CSV file with panda in Python, you may encounter such an error:
TypeError: invalid type comparison
Invalid type comparison
At this time, you can print the data in your dataframe
1. There may be no data in some items, which will be displayed as Nan when printing. Nan can’t be compared with any data, and it’s not equal to any value, including himself (so you can also use a= A to judge whether a is Nan
Therefore, in the following data processing, if a comparison operation is performed, an error will be reported:
Typeerror: invalid type comparison
the solution is to add parameters when reading the CSV
keep_ default_ Na = false
in this way, entries without data will be recognized as empty characters instead of Nan
2. Maybe the data types of different columns in your dataframe are different. Some of them are recognized as STR and some as int. although they all look like numbers, they will also report errors when compared later
At this time, you can add a parameter
Converters = {from ‘: STR,’ to ‘: STR} # convert both from column and to column to STR type
converters are interpreted as follows:
converters : dict, default None
Dict of functions for converting values in certain columns. Keys can either
be integers or column labels
After the same type, they can be compared together
Similar Posts:
- Python Pandas: Read_Excel() and to_Excel() function
- [Solved] TypeError: string indices must be integers, not str
- Python pandas merge cannot merge two data frames based on column names (Key Error)?
- [Solved] Tensorflow TypeError: Fetch argument array has invalid type ‘numpy.ndarry’
- PaddlePaddle Error: ‘map’ object is not subscriptable
- TypeError: list indices must be integers or slices, not str
- Python3: list dict set [UNK]unhashable type
- When mysql creates a table, set timestamp DEFAULT NULL error 1067-Invalid default value for’updated_at’
- [Solved] Oracle :value too large for column “SCHEMA”.”TABLE”.”COLUMN” (actual: 519, maximum: 500)
- Tableau must know and must know how to make an intuitive waffle chart