0

I opened a CSV with Pandas DataFrame and I want to delete lines with NaN, only after the 3rd column.

Ex:

Country Name Country Code Series 1970 1980 1990
France FR AFT32 NaN NaN NaN
Brasil BR AFT33 NaN 34 NaN
Spain SP AFT34 NaN NaN NaN
Portugal PT AFT35 27 NaN 86
Italy IT AFT36 NaN NaN 99

For this example, I only want deletes lines France and Spain because they have just NaN after the 3rd column.

Henry Ecker
  • 34,399
  • 18
  • 41
  • 57
Clamo
  • 1
  • 2
    https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.dropna.html#pandas.DataFrame.dropna – Paul H Oct 29 '21 at 15:10

1 Answers1

0

Specify a list of column names and use pandas.DataFrame.dropna():

df.dropna(axis=0, subset=['1970', '1980', '1990'], inplace=True)
Bashton
  • 339
  • 1
  • 11