'how to combine dataframes having multiple rows with index of 0
I have 2 dataframes that have multiple rows with index of 0. I was trying to combine both but I am getting only one row. How can I get all rows?
Df1
IDD INN
0 1400.0
IDD INN
0 1500.0
Df2
FAD INN
0 4200.0
FAD INN
0 2400.0
I am using below statement to combine but I see only row in output
import pandas as pd
result = pd.concat([df1, df2], axis=1, join='inner')
output:
IDD INN FAD INN
0 1500.0 2400.0
Below is the constructor:
{'IDD INN': {0: 1500.0}}
{'FAD INN': {0: 2400.0}}
Solution 1:[1]
Do you need join?
>>> df1.join(df2, how='outer')
INDIVIDUAL DEDUCTIBLE INN FAMILY DEDUCTIBLE INN
0 1400.0 4200.0
0 1400.0 2400.0
0 1500.0 4200.0
0 1500.0 2400.0
Setup:
>>> df1
INDIVIDUAL DEDUCTIBLE INN
0 1400.0
0 1500.0
>>> df2
FAMILY DEDUCTIBLE INN
0 4200.0
0 2400.0
Or concat
>>> pd.concat([df1, df2], axis=1)
INDIVIDUAL DEDUCTIBLE INN FAMILY DEDUCTIBLE INN
0 1400.0 4200.0
0 1500.0 2400.0
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
