I'm trying to remove duplicates values and blanks in my dataframe, and then reorder all the values so that in a row, all column values end with same number:
THIS IS MY CURRENT DATAFRAME:
brand code des price year
0 brand1 code1 des1 price1 year1
1 brand2 code2 price2
2 brand3 code3 des3 price3 year3
3 brand4 code4 price4
4 brand5 code5 des5 price5 year5
5 brand6 code6 price6
6 code2 des2 year2
7 code4 des4 year4
8 code6 des6 year6
THIS IS WHAT I WANT AS OUTPUT:
brand code des price year
0 brand1 code1 des1 price1 year1
1 brand2 code2 des2 price2 year2
2 brand3 code3 des3 price3 year3
3 brand4 code4 des4 price4 year4
4 brand5 code5 des5 price5 year5
5 brand6 code6 des6 price6 year6
This is the code I wrote, if someone can guide me how can I do it, that would be really appreciated:
import pandas as pd
data = {
'code': ['code1','code2','code3','code4','code5','code6','code2','code4','code6'],
'des': ['des1','','des3','','des5','','des2','des4','des6'],
'price': ['price1','price2','price3','price4','price5','price6','','',''],
'year': ['year1','','year3','','year5','','year2','year4','year6'],
'brand': ['brand1','brand2','brand3','brand4','brand5','brand6','','','']
}
df = pd.DataFrame.from_dict(data)
print(df)