0

Working on my first data project and I'm new to stackoverflow. All the other examples I have found use append, but whenever I try append, the data gets organized wrong since I want to concatenate the columns vertically. This is what I have so far:

import pandas as pd
import os

input_file_path = "C:/Users/laura/Downloads/excel files/"
output_file_path = "C:/Users/laura/OneDrive/Desktop/master excel/"

excel_file_list = os.listdir(input_file_path)
df = pd.DataFrame()

for excel_files in excel_file_list:
    if excel_files.endswith('.csv'):
        df1  = pd.read_csv(input_file_path+excel_files)
    df = pd.concat(df1, axis=1, ignore_index=True) 

And this is the error I am getting:

TypeError: first argument must be an iterable of pandas objects, you passed an object of type "DataFrame"
Laura
  • 1

2 Answers2

0

Simply do this: (File1 and File2 are the paths to the [.csv]/excel files)

dataFrame = pd.concat(
   map(pd.read_csv, [file1, file2]), ignore_index=True)

Make sure your paths are something like this:

C:\username\folder\1.csv

Thornily
  • 533
  • 3
  • 15
0

Hy Laura, try this:

df1 = pd.read_csv("Directory/file.csv",sep=';')
df2 = pd.read_csv("Directory/file.csv", sep=';')
df = pd.concat([df1, df2])

I usually d'ont use

df = pd.DataFrame()

Directly I put the line

df = pd.concat([df1, df2])

Be careful because in some exel files, you have to modify the atribute 'sep' of function pd.read_csv.

I hope have you helped.