There is an article that says that the column containing NaN is extracted, but there was no one that specifically fetched each column or filled that column with another list, so I will summarize it this time. It was. As for the explanation, since it is a beginner, it may not be very helpful, but I hope you can see it to the extent that there is such a method.
The code that returns True when NaN is included somewhere in the line is If you want to return True only when all the lines are NaN, you can change any to all. In the data prepared this time, only the second line contains NaN.
df_judge = df.isnull().any(axis=1) """ 0 False 1 False 2 True 3 False 4 False 5 False 6 False 7 False 8 False 9 False """
First, I could check if True existed with an if statement, which was almost the same as calling an element of a list.
for i in range(len(df)): if df_judge[i] == True: for j in range(len(df.columns)): #Round processing is processing that aligns to the first decimal place df.iloc[i,j] = average_list[j]
This time the goal was to insert the mean of the other columns into one column with NaN. Since the number of columns and the number of rows can be obtained with len (df) and len (df.columns), I used the double for statement. After it is determined that there is NaN in the if statement, the column is shifted one by one to the specified row and the average value is assigned. I used df.iloc [row, column] to specify the elements of the DataFrame. It's a pity that you can't insert each column directly, but you can handle it this way, so please refer to it.