I have the following data set:
1 8 15 22
2 9 16 23
3 10 17 24
4 11 18 25
5 12 19 26
6 13 20 27
7 14 21 28
I want to get the following result:
1
2
3
4
5
6
7
8
...
23
24
25
26
27
28
So I want to loop over all columns of my dataset and concat each column to the first one.
import pandas as pd
df = pd.read_csv("data.csv", delimiter=";", header=-1)
number_of_columns= len(df.columns)
print(number_of_columns)
for i in range (1,number_of_columns):
df1 = df.iloc[:,i]
df2 = pd.concat([df,df1], ignore_index=True)
print(df2)
With this only the last column is concatenated in the final dataframe. I get it that df2 is overwritten in each iteration of the for-loop.
So how can I "save" df2 after each for loop so that every column is concantenated?
Thanks a lot!
df.unstack()