This is my original DF in pandas.
I've tried to combine the first 5 rows into one row by using: combine_first, but I can't achieve it.
Also I've followed this answer: How to merge two rows in a dataframe pandas. Any suggestions?
This is my original DF in pandas.
I've tried to combine the first 5 rows into one row by using: combine_first, but I can't achieve it.
Also I've followed this answer: How to merge two rows in a dataframe pandas. Any suggestions?
option 1
pd.DataFrame.bfill
df.bfill().iloc[[0]]
option 2
pd.DataFrame.lookup
pd.DataFrame(
df.lookup(df.apply(pd.Series.first_valid_index), df.columns),
df.columns).T
option 3
numpy.argmax
v = df.values
pd.DataFrame(
v[(~np.isnan(v)).argmax(0), np.arange(v.shape[1])].reshape(1, -1),
columns=df.columns)
All yield
time testing