python 3.x - How to merge several dataframes from a folder into a single dataframe? -


i have folder of csv files , each file has dataframe looks this. here examples of 2 of dataframes:

df1 & df2:

name     level meg      1 ben      2 andy     3 vern     4 oscar    5  name     level hanna    1 ron      2 sal      3 

this code have far reads in dataframes within folder:

def match_folder(folderpath, exportfile):     vals = []     directory = os.fsencode(folderpath)     os.chdir(directory)     file in os.listdir(directory):         filename = os.fsdecode(file)         if filename.endswith(".csv"):             df1 = pd.read_csv(filename)             vals.append(df1) 

not sure after point.

i want final output be:

name     level meg      1 ben      2 andy     3 vern     4 oscar    5 hanna    1 ron      2 sal      3 

iiuc can use pd.concat() method:

import glob  df = pd.concat([pd.read_csv(f) f in glob.glob('/path/to/*.csv')], ignore_index=true) 

Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -