I have the below table taken online through pandas.read_html
Column0 Column1 Column2 Column3
0 Entry_1 0.685 Record_1 0.69-S$ 0.685
1 Entry_2 0.036 Record_2 0.685
2 Entry_3 05/Jul/2016 Record_3 0.72-S$ 0.4
3 Entry_4 0.338 Record_4 178.8 mm
4 Entry_5 0.41 Record_5 0.06
5 Entry_6 122.48 Record_6 17.29%
6 Entry_7 0.5 Record_7 0.58 as of 05/Jul/2016
How do I pviot / transpose this data such that Column 0
becomes the headers, and Column 1
becomes the values. Similarly for Column 2
and Column 3
?
This is probably the easiest way to solve this problem. The easiest way I could come up with anyway.
Column0 Column1 Column2 Column3
0 Entry_1 0.685 Record_1 0.69-S$ 0.685
1 Entry_2 0.036 Record_2 0.685
2 Entry_3 05/Jul/2016 Record_3 0.72-S$ 0.4
3 Entry_4 0.338 Record_4 178.8 mm
4 Entry_5 0.41 Record_5 0.06
5 Entry_6 122.48 Record_6 17.29%
6 Entry_7 0.5 Record_7 0.58 as of 05/Jul/2016
cols = df['Column0'].append(df['Column2'])
vals = df['Column1'].append(df['Column3'])
newdf = pd.DataFrame(vals).T
newdf.columns = cols
newdf
Entry_1 Entry_2 Entry_3 Entry_4 Entry_5 Entry_6 Entry_7 Record_1 Record_2 Record_3 Record_4 Record_5 Record_6 Record_7
0 0.685 0.036 05/Jul/2016 0.338 0.41 122.48 0.5 0.69-S$ 0.685 0.685 0.72-S$ 0.4 178.8 mm 0.06 17.29% 0.58 as of 05/Jul/2016
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments