votes up 4

cannot convert the series to (converter)

github stars 30911
Exception Class:

Raise code

    Install the scalar coercion methods.

    def wrapper(self):
        if len(self) == 1:
            return converter(self.iloc[0])
        raise TypeError(f"cannot convert the series to {converter}")

    wrapper.__name__ = f"__{converter.__name__}__"
    return wrapper

# ----------------------------------------------------------------------
# Series class
😲  Walkingbet is Android app that pays you real bitcoins for a walking. Withdrawable real money bonus is available now, hurry up! 🚶

Ways to fix

votes up 2 votes down

Summary: Cannot convert Series type to scalar type like int, float, and long

Code to reproduce (WRONG):

import pandas as pd

df = mock_df = pd.DataFrame(data={
    'A': [1,2,3]

int(df['A']) #Try to convert Series to an integer will throw the exception

Working version (Fixed)

import pandas as pd

df = mock_df = pd.DataFrame(data={
    'A': [1,2,3]

int("1") # convert string to integration is ok
Jun 06, 2021 phoang88 answer
phoang88 615

Add a possible fix

Please authorize to post fix