Retain few NA's and drop rest of NA's during Stack operation in Python

前端 未结 3 1335
悲&欢浪女
悲&欢浪女 2020-12-04 04:14

I have a dataframe like shown below

df2 = pd.DataFrame({\'person_id\':[1],\'H1_date\' : [\'2006-10-30 00:00:00\'], \'H1\':[2.3],\'H2_date\' : [\'2016-10-30          


        
3条回答
  •  情书的邮戳
    2020-12-04 04:52

    You can use :

    col = [x for x in df.columns if "date" in x] for column in col: df.dropna(subset=[column,column[:-4]], how = 'all',inplace=True)

    subset will select the lines where the NA is detected, how specifies the conditions on the line (here all the of the 2 lines must be NA) and inplace modifies the current DataFrame

提交回复
热议问题