PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, August 27, 2022

[FIXED] How to merge three different csv files into one Python Panda

 August 27, 2022     csv, pandas, python     No comments   

Issue

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

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)


Answered By - Shashwat
Answer Checked By - Pedro (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing