Я думаю, что заслуживаю +1
для восстановления ваших данных; D
import pandas as pd
import numpy as np
# Create DataFrame
rows = []
rows.append({'ID': 1, 'col_1': ' ', 'col_2':'20', 'col_3': '40'})
rows.append({'ID': 1, 'col_1': '10', 'col_2': ' ', 'col_3': ' '})
rows.append({'ID': 1, 'col_1': '50', 'col_2':' ', 'col_3': '60'})
rows.append({'ID': 3, 'col_1': '40', 'col_2':'10', 'col_3': '90'})
rows.append({'ID': 4, 'col_1': ' ', 'col_2':'80', 'col_3': '80'})
df = pd.DataFrame(rows)
#Clean it by replacing whitespaces with nan
clean_df = df.replace(r'\s+', np.nan, regex=True)
# Group on ID and take the first
clean_df.groupby('ID').first()
print(clean_df)