How to remove rows with null values from kth column onward in python

You can call dropna with arguments subset and how:

df2.dropna(subset=['three', 'four', 'five'], how='all')

As the names suggests:

  • how='all' requires every column (of subset) in the row to be NaN in order to be dropped, as opposed to the default 'any'.
  • subset is those columns to inspect for NaNs.

As @PaulH points out, we can generalise to drop the last k columns with:

subset=df2.columns[k:]

Indeed, we could even do something more complicated if desired:

subset=filter(lambda x: len(x) > 3, df2.columns)

Leave a Comment

How to remove rows with null values from kth column onward in python

You can call dropna with arguments subset and how:

df2.dropna(subset=['three', 'four', 'five'], how='all')

As the names suggests:

  • how='all' requires every column (of subset) in the row to be NaN in order to be dropped, as opposed to the default 'any'.
  • subset is those columns to inspect for NaNs.

As @PaulH points out, we can generalise to drop the last k columns with:

subset=df2.columns[k:]

Indeed, we could even do something more complicated if desired:

subset=filter(lambda x: len(x) > 3, df2.columns)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)