0

I have the following script:

import pandas as pd
import numpy as np

df = pd.read_csv("scedon_etoimo.csv")

df.replace(np.nan, '', regex=True)

if df[(df['ship_from'].str.contains('<')) | (df['ship_from'].str.contains(' '))]:
  print(df['ship_from'])

In the csv I have the last column which contains either string or NaN or < Name_of_a_country / strong> (my purpose is to replace those with another string). But when I run it to see if my statement works, I get the following error :

ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()

I have already checked this topic

Any help?

Gerasimos
  • 279
  • 2
  • 8
  • 17
  • 1
    `df['ship_from'].str.contains("<|' '")` – BENY Sep 24 '18 at 18:54
  • 1
    You can't use `if` with dataframes as the error tells you, because they have more than value and python does not how to assess its truthfulness. You can call `len()` on your `df[(df['ship_from'].str.contains('<')) | (df['ship_from'].str.contains(' '))]` and check if it has elements inside. – hellpanderr Sep 24 '18 at 18:56
  • Did you read the answers to the question you linked? If you did, why are you trying to use a `pandas.DataFrame` as a boolean condition? – juanpa.arrivillaga Sep 24 '18 at 19:09

0 Answers0