question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DataFrame.replace: TypeError: Cannot compare types 'ndarray(dtype=int64)' and 'unicode'

See original GitHub issue

Code 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:closed
  • Created 6 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
diegoquintanavcommented, Dec 28, 2017

I’m having the same problem. I say a flag like the one that to_numeric has would do great here.

2reactions
TomAugspurgercommented, Jun 28, 2017

For consistency, and since replace is a general purpose find / replace method, it’d be nice if this didn’t raise a TypeError.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found