How to correctly merge multiple csv files in Python

199
July 25, 2021, at 04:50 AM

How can I correctly merge multiple csv files with, in most cases, different column names between each file? I have tried using .concat() in the following code:

import os, glob
path = "mypath/"
all_files = glob.glob(os.path.join(path, "*.csv"))
df_from_each_file = (pd.read_csv(f, sep=',') for f in all_files)
df_merged   = pd.concat(df_from_each_file, axis=0,
    join="outer",
    ignore_index=False,
    keys=None,
    levels=None,
    names=None,
    verify_integrity=False,
    copy=True,)
df_merged.to_csv('mypath/my_new_file.csv')
my_new_file = pd.read_csv ('mypath/my_new_file.csv', sep=',')
print(my_new_file.head(40))
print(my_new_file.columns)

I know some of the .csv share some column names but they don't get merged correctely. Am I missing something?

Do you advice using .merge() instead? Thank you

Rent Charter Buses Company
READ ALSO
Embed svg in safari doesn't able to call the click event in safari browser

Embed svg in safari doesn't able to call the click event in safari browser

Embed svg in safari doesn't able to call the click event in safari browser

135
React socket io client emitting twice to node server

React socket io client emitting twice to node server

I am making a react app with node as backendThey communicate using socket-io

168
Finding child views from parent view created programmatically in Android

Finding child views from parent view created programmatically in Android

For an Android App, I'm using a GridView and extending BaseAdapter to organize its contentsFor the function getView that I override in my extended BaseAdapter class, I create a LinearLayout, which I attach an ImageView and 3 TextViews to

145
What do the different plans of NSolid SaaS include?

What do the different plans of NSolid SaaS include?

I'm interested on testing NSolid for my Nodejs app, and saw there is a new SaaS version

114