Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concat not working as expected

I have 2 files

  • 1st Containing Data (No Column Header)
  • 2nd Containing Column Header

I want to combine this 2 into 1 file. My approach push the data into dataframe and used concat on them get the file result set.

My Code Till now

import pandas as pd
from xlrd import open_workbook

#contains mapping, Column present
#DataFileName   FolderLocation  ColumnFileName
#Data1           F:\Desktop      ColFile1
#Data2           F:\Desktop      ColFile2

filelocation = 'F:\Desktop\Mapping.xlsx'
wb = open_workbook(filelocation)
Separator = ','
items = []
for sheet in wb.sheets():
    number_of_rows = sheet.nrows
    number_of_columns = sheet.ncols
    for row in range(1, number_of_rows):
        for col in range(number_of_columns):
            ColumnFileName = sheet.cell(row,0).value
            Path = sheet.cell(row,1).value
            DataFileName = sheet.cell(row,2).value

            DataFileCompName = Path + "\\" + DataFileName +FileExtension
            ColumnFileCompName = Path + "\\" + ColumnFileName+ FileExtension
            HeaderDataFrame = pd.read_csv(ColumnFileCompName,sep=Separator)#,index_col=0)#,header=0)
            DataDataFrame = pd.read_csv(DataFileCompName,sep=Separator)#,header=None)

            CompleteDataFrame = pd.concat([HeaderDataFrame,DataDataFrame], ignore_index=True,axis=1)

Now, With concat i want the result set as

HeaderDataFrame
DataDataFrame

Whereas i am getting result as

HeaderDataFrame|DataDataFrame
like image 566
Sachin Kamble Avatar asked Jan 24 '26 06:01

Sachin Kamble


1 Answers

you need to change the axis from axis=1 to axis=0 in your code, so

CompleteDataFrame = pd.concat([HeaderDataFrame,DataDataFrame], ignore_index=True,axis=0)
like image 129
Imran Avatar answered Jan 25 '26 20:01

Imran



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!