One way to bind dataframes by row in Python is to use the pandas concat()
function with axis=0
. This function concatenates dataframes along a particular axis. Here is an example:
main.py240 chars11 lines
Output:
main.py40 chars6 lines
In this example, df1
and df2
are concatenated by row with pd.concat([df1, df2], axis=0)
. The resulting dataframe df_concat
contains the rows of both dataframes stacked on top of each other. Note that the index is not reset, resulting in duplicated index values.
gistlibby LogSnag