To horizontally concatenate pandas dataframes in Python, you can use the concat
function from the pandas library. Here is an example:
main.py299 chars14 lines
This will output the concatenated dataframe:
main.py60 chars5 lines
In the concat
function, we pass a list of dataframes to be concatenated as the first argument. The axis=1
parameter indicates that the concatenation should be done horizontally.
Note that the dataframes being concatenated should have the same number of rows, otherwise pandas will raise a ValueError
.
gistlibby LogSnag