2

Dataframe:

    Date and time      Transaction Date   Transcation currency  Card currency                           Description
0    21.12.2021 14:31       21.12.2021           + 500,00 ₽    + 500,00 ₽   Внутрибанковский перевод с договора 52876*****
1    21.12.2021 15:43       21.12.2021           - 454,00 ₽    - 454,00 ₽    Оплата в KFC AVIAMOTORNAYA.2 Gorod Moskva RUS
2    21.12.2021 22:29       21.12.2021            + 16,98 ₽     + 16,98 ₽                              Проценты на остаток
3    21.12.2021 22:56       21.12.2021           + 887,00 ₽    + 887,00 ₽                        Кэшбэк за обычные покупки
4    21.12.2021 23:15       21.12.2021            - 59,00 ₽     - 59,00 ₽                 Плата за оповещения об операциях
..                ...              ...                  ...           ...                                              ...
330  19.03.2022 21:32       19.03.2022         + 1 200,00 ₽  + 1 200,00 ₽   Внутрибанковский перевод с договора 5287*****
331  20.03.2022 01:06       21.03.2022            - 50,50 ₽     - 50,50 ₽    Операция в других кредитных организациях QIWI
332               NaN              NaN                  NaN           NaN                                       MOSKVA RUS
333  21.03.2022 12:43       21.03.2022            - 10,00 ₽     - 10,00 ₽  Внешний перевод по номеру телефона +79263******
334  21.03.2022 12:43       21.03.2022            - 30,00 ₽     - 30,00 ₽                      Комиссия за внешний перевод 

                    

I have a piece of code that iterates over the data frame by column:

for index, row in df.iterrows():
    print(row["Date and time"])

I need to delete the rows where it is NaN. How do I do that? I have tried .isnull() and .notnull() but they return Errors

GoatMode
  • 23
  • 2

1 Answers1

1

Use a boolean mask. I assume you loaded the data frame and 'Nan' is read as a string:

df = df[df["Date and time"]!='NaN']
Sala
  • 480
  • 4
  • 19
  • 1
    This won't actually work. You need to do `df[df["Date and time"].notna()]` because `NaN == NaN` is always `False`. Or preferably you could do `df = df.dropna()`. Also, please don't answer duplicate questions :) –  Mar 25 '22 at 14:37