I would like to append the row(s) that have unique values (excluding empty cells) from df1 to an empty df2.
The structure of df1 is like this:
idx A1 B1 C1 A2 B2 C2
---------------------------------------
I1 n n b c
J1 x x x x x x
K1 a b c d e f
So in this case, row K1 will be appended to df2 because all the values are unique.
To append the row, I tried
df2 = pd.DataFrame()
df2 = df2.append(df1.loc['K1'],sort=False)
I was expecting
idx A1 B1 C1 A2 B2 C2
---------------------------------------
K1 a b c d e f
But actually I got
idx A1 A2 B1 B2 C1 C2
---------------------------------------
K1 a d b e c f
Looks like the columns were sorted, even I set sort=False. I know I can hard code it as
df2 = df2.append({'idx':idx,'A1':df1.loc[idx,'A1'],'A2':df1.loc[idx,'A2'],'B1':df1.loc[idx,'B1']...})
to achieve what I want. But my actual file has 30+ columns and it's impossible to hard code every column.