简体   繁体   中英

Merging rows of a dataframe into single one using python

I am doing some stuff using pandas in python and came across one dataset that needs to be clean. It looks likes this- 在此处输入图片说明

I need to merge rows of index 0,1,2,3 into 1 single row by avoiding NaN value. Also, after doing this, I want to remove the default header and make the newly made row the default name for columns. I tried to use groupby operation in pandas but nothing is happening. Any idea on this?

Thanks Akhi

pd.DataFrame([df.aggregate(lambda x:" ".join(str(e).strip() for e in x if not pd.isna(e))).tolist()],columns=[<add_new_list这里>])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM