0

I want to concatenate multiple columns of Excel into single column using Python. Please find below the format:

enter image description here

and after concatenate it will make single column:

enter image description here

How can I do this?

halfer
  • 19,824
  • 17
  • 99
  • 186
Sourav_Bharadwaj
  • 175
  • 3
  • 11
  • Does this answer your question? [How to concatenate multiple column values into a single column in Panda dataframe](https://stackoverflow.com/questions/39291499/how-to-concatenate-multiple-column-values-into-a-single-column-in-panda-datafram) – Mayank Porwal Jul 17 '20 at 10:53
  • Thanks It's working. Actually I am importing the data from Excel. Still it's help me – Sourav_Bharadwaj Jul 17 '20 at 11:37

1 Answers1

0
  • Load your ".csv" file to a DataFrame
  • Get the column names
  • Iterate through to concatenate the columns with apply function
  • Store the DataFrame
import pandas as pd

output = pd.read_csv('../filename.csv')

cols = output.columns

df_new = output[cols].apply(lambda row: ' '.join(row.values.astype(str)), axis=1)

df_new.to_csv('../filename_new.csv', sep='\t')

Olasimbo
  • 965
  • 6
  • 14