bind dataframes by row in python in python

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.py
import pandas as pd

# create two example dataframes
df1 = pd.DataFrame({'A': [1, 2], 'B': [3, 4]})
df2 = pd.DataFrame({'A': [5, 6], 'B': [7, 8]})

# concatenate dataframes by row
df_concat = pd.concat([df1, df2], axis=0)

print(df_concat)
240 chars
11 lines

Output:

main.py
   A  B
0  1  3
1  2  4
0  5  7
1  6  8
40 chars
6 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