Suppose I have a dataframe as follows
C1 C2
0 A B
1 C NaN
2 E F
3 G H
how can I merge the two columns into one using pandas
output
new
0 A
1 B
2 C
3 NaN
4 E
5 F
6 G
7 H
Suppose I have a dataframe as follows
C1 C2
0 A B
1 C NaN
2 E F
3 G H
how can I merge the two columns into one using pandas
output
new
0 A
1 B
2 C
3 NaN
4 E
5 F
6 G
7 H
Use DataFrame constructor with converted DataFrame to numpy array:
df = pd.DataFrame({'new':df.values.ravel()})
Or stack with reset_index:
df = df.stack(dropna=False).reset_index(drop=True).to_frame('new')
print (df)
new
0 A
1 B
2 C
3 NaN
4 E
5 F
6 G
7 H