Home > Mobile >  How to merge three different csv files into one Python Panda
How to merge three different csv files into one Python Panda

Time:08-11

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

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

CodePudding user response:

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)

CodePudding user response:

If I understand it right, you don't want to concat vertically but horizontally. Right?

Try this:

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

  • Related