I have A dataframe as below:
Car SeriesNo White Red Black
Proton A111 2
Proton A111 4
Proton A111 5
My Expected output will be:
Car SeriesNo White Red Black
Proton A111 2 4 5
Anyone have ideas on this?
asked Sep 2, 2019 at 4:47
-
There are multiple groups by first 2 columns?jezrael– jezrael2019年09月02日 04:51:43 +00:00Commented Sep 2, 2019 at 4:51
1 Answer 1
Use GroupBy.first
for get first non missing values per groups:
#if necessary replace empty strings to missing values
#df = df.replace('',np.nan)
df = df.groupby(['Car','SeriesNo'], as_index=False).first()
print (df)
Car SeriesNo White Red Black
0 Proton A111 2.0 4.0 5.0
answered Sep 2, 2019 at 4:50
lang-py