Newton
asked on
Python : concat 2 column in dataframe.
How to concat 2 column in pandas dataframe
My input file is
File1
CountryA|Apple|200
CountryB|Apple|100
CountryA|Orange|150
Output I need is below
CountryAApple|200
CountryBApple|100
CountryAOrange|150
I tried below code. Is this the correct way of doing this..
df1 = pd.read_csv('file1','|')
df2 = df1.iloc[:,:0]
df3 = df1.iloc[0:,:1]
df4 = df1.iloc[1:,:2]
df5 = pd.concat([df2, df3])
df6 = df5+"|"+df4
Print(df6)
My input file is
File1
CountryA|Apple|200
CountryB|Apple|100
CountryA|Orange|150
Output I need is below
CountryAApple|200
CountryBApple|100
CountryAOrange|150
I tried below code. Is this the correct way of doing this..
df1 = pd.read_csv('file1','|')
df2 = df1.iloc[:,:0]
df3 = df1.iloc[0:,:1]
df4 = df1.iloc[1:,:2]
df5 = pd.concat([df2, df3])
df6 = df5+"|"+df4
Print(df6)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER