0

I have multiple dataframes that I'd like to join together vertically. Each one is ~90 rows and 3 columns so I'd like it to be ~500 rows and 3 columns. When I use pd.concat to do this though it puts the second dataframe in an additional 3 columns meaning I have 6.

import pandas as pd

pd.set_option('display.max_columns', None)  
pd.set_option('display.max_rows', None)  
pd.set_option('display.width',1000)

df1 = pd.read_csv("file1.txt",delim_whitespace=True, skiprows=1, on_bad_lines='skip')
df1 = df1.iloc[:,[10,11,12]]
df2 = pd.read_csv("file2.txt",delim_whitespace=True,skiprows=1,on_bad_lines='skip')
df2 = df2.iloc[:,[10,11,12]]

x = pd.concat([df1, df2])
print(x)

The first dataframe is on the left and the second on the right with spaces being NaN

I thought the pd.concat would combine both dataframes into 1 dataframe with all the rows of df1 and df2 but with 3 columns.

  • use `x = pd.concat([df1, df2], axis=1)`, if this is not what you want, please provide a **minimal reproducible example** (i.e. two small `DataFrame`s as code/text, and the expected output) – mozway Mar 09 '23 at 12:43
  • I'd like to combine multiple dataframes vertically. I'd like the contents of the second dataframe to be added underneath the first dataframe in the same 3 columns. – Jordan Allen Mar 09 '23 at 14:51

0 Answers0