Here I am trying to concat dataframe A and B with C using a for loop.
data = [['Alex',10],['Bob',12],['Clarke',13]]
A = pd.Dataframe(data, columns=['Name','Age'])
B = pd.Dataframe(data, columns=['Name','Age'])
C = pd.Dataframe(data, columns=['Name','Age'])
A.columns ---> Index(['Name', 'Age'], dtype='object')
B.columns ---> Index(['Name', 'Age'], dtype='object')
C.columns ---> Index(['Name', 'Age'], dtype='object')
for df in [A, B]:
df = pd.concat([df, C], axis=1)
A.columns ---> Index(['Name', 'Age'], dtype='object')
B.columns ---> Index(['Name', 'Age'], dtype='object')
df.columns ---> Index(['Name', 'Age', 'Name', 'Age'], dtype='object')
Why its not concatenating C with original A, B dataframes. Why it is creating a new df Dataframe?
I want after for loop:
A.columns ---> Index(['Name', 'Age', 'Name', 'Age'], dtype='object')
B.columns ---> Index(['Name', 'Age', 'Name', 'Age'], dtype='object')