1

Seems kinda simple but havent been able to find a fix for this idea on Google, YouTube, or Stackoverflow.

Essentially if one panda df like this:

A | B
-----
45| 98

And then another panda df like this:

X  | Y
------
67 | 2

Is there a way to structure/combine the two together like this:

df_merged = pd.DataFrame([df1,df2])

And generate a complete panda df like:

    A | B
    -----
    45| 98

    X  | Y
    ------
    67 | 2

Can a row be created in the middle to separate between the top df and bottom df?

Is it possible?

Thank you

JimR4729
  • 33
  • 1
  • 3
  • I don't think this is possible. What is your end goal? Perhaps there is a better solution. – jkr Feb 24 '21 at 21:10

1 Answers1

0

Dataframe is a table-like data structure. It can have multiple indexes, but what's inside is still something unified, meaning that viewing it as just 2 different tables with individual headers is contrary to the idea of what it is.

That said, you can make an new upper row filled with NaNs, then make the next row duplicate the column names, and then concat your 2 tables. It won't be exactly the same as having 2 tables, but will sort of mimic it. However I'd strongly discourage you against that. Dataframes are used for calculations, not for in-line visualizations, and it sounds very much like you are trying to perceive them as an Excel like instrument, which combines viewing UI with calculation capacities. When you need to visualize a dataframe, you need to plot it.

delimiter
  • 745
  • 4
  • 13