'Why a NaT appeared at the end of my dataframe after use drop pandas?

I have a dataframe and I'm excluding some rows based on certain conditions related to the existence of NaN in that row. But, after running the code below, it appears at the dataframe end (as shown in the image) a new row is formed by NaT and unknown numbers. I wanted to know how this NaT came and how to avoid it. I think there are some relation with "df2.drop(df2.index[i])".

nan_location = df2.isnull()

first_columns = list(range(1,len(df.columns)))
second_columns = list(range(len(df.columns), len(df2.columns)))


for i in range(len(nan_location)):
    
    if True in list(nan_location.iloc[i]):
        
        if list(np.where(list(nan_location.iloc[i]))[0]) == first_columns:
            
           if list(np.where(list(nan_location.iloc[i+1]))[0]) == colunas_segundo:
               
               for colunas in second_columns:
                   df2.at[i+1, df2.columns[colunas]]=df2[df2.columns[colunas]][i]
                   
               df2=df2.drop(df2.index[i])
               
         
        elif list(np.where(list(nan_location.iloc[i]))[0]) == second_columns:
            
            if list(np.where(list(nan_location.iloc[i+1]))[0]) == first_columns:
                
                for colunas in first_columns:
                   df2.at[i+1, df2.columns[colunas]]=df2[df2.columns[colunas]][i]
                  
                df2=df2.drop(df2.index[i])

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source