-4

I an using the following for loop to iterate over df (droping a row if condition match) :

for index, row in df.iterrows():
   if(pd.isnull(row["CR Date"])):
     df.drop(index, inplace=True)

the df shape 240,000*30 It is working BUT It is taking more than 1.5 hours. Is there any faster way? I am using Anaconda JupyterLab

syedmfk
  • 111
  • 1
  • 1
  • 4

1 Answers1

0

replace:

for index, row in df.iterrows():
   if(pd.isnull(row["CR Date"])):
     df.drop(index, inplace=True)

by this to drop rows with missing value:

df.dropna(subset=['CR Date'], inplace=True)

for more information, please look at: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.dropna.html

Cao Minh Vu
  • 1,900
  • 1
  • 16
  • 21