Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to merge three different csv files into one Python Panda

I am relativly new to Python and I have a question:
How can I merge the data from three different csv files?

csv1:
label

csv2:
timestamp

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

csv3:
start

I tried this:

    concate_data = pd.concat([label,timestamp,start])

It kinda works but the outcome is wrong. I got something like this:

label timestamp start
Eating null null
Eating null null
null 2012:02:02 12:00:01 null
null null 1
null null 0

How can I concat these three different csv files into one so that they look like the following?

label timestamp start
Eating 2012:02:02 12:00:01 1
Eating 2012:02:02 12:01:01 0
Eating 2012:02:02 12:01:01 0

>Solution :

All you need to do is add axis=1 to pd.concat

So, basically:

concate_data = pd.concat([label,timestamp,start], axis=1)

Example Code:

import pandas as pd

# initialize list elements
data = [10,20,30,40,50,60]
# Create the pandas DataFrame with column name is provided explicitly
df = pd.DataFrame(data, columns=['Numbers'])
print(df)

concate_data = pd.concat([df,df,df], axis=1)
print(concate_data)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading