I have two dataframes:
import pandas as pd
import numpy as np
n=10
df = pd.DataFrame(
{
"A": 1.0,
"B": pd.Timestamp("20130102"),
"C": pd.Series(1, index=list(range(n)), dtype="float32"),
"D": np.array([3] * n, dtype="int32"),
"E": pd.Categorical(["test", "train"] * int(n/2)),
"F": "foo",
}
)
i_f = ['A', 'B']
o_f = ['C', 'D', 'E', 'F']
df1 = pd.DataFrame(data=df[i_f].values, columns=i_f).reset_index(drop=True)
df2 = pd.DataFrame(data=df[o_f].values, columns=o_f).reset_index(drop=True)
df1 and df2 are dataframes with the same number of rows, and different columns. Now I want to select a row i in df1, a row j in df2, and obtain a single dataframe of a single row, which has the columns from df1 and df2. I do:
i = 3
j = 2
df_curr = pd.concat([df1.iloc[[i], :], df2.iloc[[j], :]], axis=1)
However, what I get instead is a dataframe with two rows, and with NaNs:
print(df_curr)
# A B C D E F
# 3 1.0 2013-01-02 NaN NaN NaN NaN
# 2 NaN NaT 1.0 3 test foo
Instead, I need
A B C D E F
# 1.0 2013-01-02 1.0 3 test foo
How can I get it?