DataFrame.replace: TypeError: Cannot compare types 'ndarray(dtype=int64)' and 'unicode'
See original GitHub issueCode Sample, a copy-pastable example if possible
path1 = '/some.xls'
df1 = pd.read_excel(path1)
columns_values_map={
'positive': {
'正面':1,
'中立': 1,
'负面':0
}
}
df1.replace(columns_values_map)
Problem description
got error: TypeError: Cannot compare types 'ndarray(dtype=int64)' and 'unicode'
Actually df1['positive']
only has value in (0, 1) , but I think it should not throw exception here.
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Cannot compare types 'ndarray(dtype=int64)' and 'str'
You only have int64( here actually ndarray(dtype=int64)) type data in this column. See document pandas.Dataframe.replace(). replace() try to ...
Read more >Python error TypeError Cannot compare types ndarray dtype ...
I'm trying to execute the following python code: import pandas as pd csv_file = 'sample.csv' count ... )' and 'str' Process finished with ......
Read more >Cannot Compare Types 'Ndarray(Dtype=Int64)' And ... - ADocLib
Ask questionsDataFrame.replace: TypeError: Cannot compare types 'ndarraydtypeobject' and 'str'. I have a dataset in csv and a dictionary created by a.
Read more >pandas-series-replace - w3resource
This raises a TypeError because one of the dict keys is not of the correct type for replacement. Compare the behavior of s.replace({'p':...
Read more >Cannot compare types 'ndarray(dtype=int64)' and 'str' while ...
I have a dictionary with two different datatypes (int64 and str) and a dataframe. I am trying to replace data in the second...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m having the same problem. I say a flag like the one that
to_numeric
has would do great here.For consistency, and since
replace
is a general purpose find / replace method, it’d be nice if this didn’t raise aTypeError
.