Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8889389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:15:02+00:00 2026-06-14T22:15:02+00:00

I have two CSV files with different number of columns and rows. The first

  • 0

I have two CSV files with different number of columns and rows. The first CSV file has M columns and N rows, the second has H columns and G rows. Some of the columns have the same name.

I’d like to combine the two into data frame with following properties:

  • N+G rows
  • Union of (M, H) columns
  • if column A is element of first CSV file but not of second, the data frame should contain the same values in first N entries of A as in first CSV, and for the rest (since there is no A data in second CSV) should be NA.

Here is an example:

CSV1
City, Population,
Zagreb, 700000,
Rijeka, 142000

CSV2
City, Area,
Split, 200.00
Osijek, 171.00
Dubrovnik, 143.35

I’d like build a data frame that looks like this:

City      Population   Area
Zagreb    700000       NA
Rijeka    142000       NA
Split     NA           200.00
Osijek    NA           171.00
Dubrovnik NA           143.35

Also what if instead two CSV files I had two data frames and wanted to do the same, for example if I loaded first csv to df1 and second one in df2 and then wanted to make a merge to df3 that would look like example above.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T22:15:04+00:00Added an answer on June 14, 2026 at 10:15 pm

    Why not try the concat function:

    In [25]: df1
    Out[25]: 
         City  Population
    0  Zagreb      700000
    1  Rijeka      142000
    
    In [26]: df2
    Out[26]: 
            City    Area
    0      Split  200.00
    1     Osijek  171.00
    2  Dubrovnik  143.35
    
    In [27]: pd.concat([df1,df2])
    Out[27]: 
         Area       City  Population
    0     NaN     Zagreb      700000
    1     NaN     Rijeka      142000
    0  200.00      Split         NaN
    1  171.00     Osijek         NaN
    2  143.35  Dubrovnik         NaN
    
    In [28]: pd.concat([df1,df2], ignore_index=True)
    Out[28]: 
         Area       City  Population
    0     NaN     Zagreb      700000
    1     NaN     Rijeka      142000
    2  200.00      Split         NaN
    3  171.00     Osijek         NaN
    4  143.35  Dubrovnik         NaN
    

    Note: the concat does have some additional options if you have slightly different requirements.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two csv file. First File has date offerid clicks orders Second File
I have two csv files. In the first file i have a list of
I have a CSV file with two different columns, one with PC names and
I have two CSV files which use @ to divide each column. The first
I have 1000 CSV files from dfr.jstor.org with two columns, KEYWORDS and WEIGHT. The
I have two csv files which store an id and some associated fields that
I have two CSV files (three columns) which I need to compare and extract
I have two matrix extracted from different csv files, One is like > matrix1[1:6,]
Have two scripts that give very different results. First using csv.reader and it works
I have two csv file ( ) I can get it to print out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.