0

my DataFrame looks like that:

DataFrame

I found this but it didn´t work for me. Drop rows containing empty cells from a pandas DataFrame

i tried

df_model['Zustand'].replace("[]", np.nan, inplace=True)

df_model.dropna(subset=['Zustand'], inplace=True)

"[]" is dtype Object. I am not sure how to deal with it.

Greets Daniele

Daniele Roos
  • 21
  • 1
  • 1
  • 2

2 Answers2

0

If the column contains 'list' objects:

df_model['Zustand'].apply(lambda x: np.nan if len(x)==0 else x)
df_model.dropna(subset=['Zustand'], inplace=True)
arpitrathi
  • 157
  • 1
  • 7
0

Let me use own data now that you didnt give me some

df_model=pd.DataFrame({'BildName':['D850', 'D876', 'D839','ETC'], 'Zustand':['Beto','kelo','[]','[]']})

Try

df_model['Zustand']=df_model['Zustand'].str.replace("\[\]", "")
df_model['Zustand'].replace('', np.nan, inplace=True)
df_model.dropna(subset=['Zustand'], inplace=True)

or apply mask

m=df_model.Zustand.str.contains('\[\]')

Change as you wanted

df_model.loc[m,'Zustand']=np.nan
df_model.dropna(inplace=True)
wwnde
  • 26,119
  • 6
  • 18
  • 32