pandas – Python: ValueError: can only convert an array of size 1 to a Python scalar when looping over rows in pd.DataFrame

pandas – Python: ValueError: can only convert an array of size 1 to a Python scalar when looping over rows in pd.DataFrame

FYI,

You will get similar error if you are applying .item to a numpy array.

You can solve it with .tolist() in that case.

pd.Series.item requires at least one item in the Series to return a scalar. If:

df[(df[date_rank] == next_home_fixture) & (df[localteam_id] == df.at[index,localteam_id])]

is a Series with length 0, then the .index.item() will throw a ValueError.

pandas – Python: ValueError: can only convert an array of size 1 to a Python scalar when looping over rows in pd.DataFrame

Leave a Reply

Your email address will not be published. Required fields are marked *