In [1]:
%run setup_env.py
In [2]:
df = pd.DataFrame(np.random.randn(10, 3))
display_html(df)
display_html(
pd.concat([df[:3], df[3:7], df[7:]], axis=0),
pd.concat([df[:3], df[3:7], df[7:]], axis=1),
pd.concat([df[:3], df[3:7], df[7:]], axis=0, join='inner'),
pd.concat([df[:3], df[3:7], df[7:]], axis=1, join='inner'),
pd.concat([df[:3], df[3:7], df[7:]], keys=['first', 'second']),
)
In [3]:
df = pd.DataFrame(np.random.randn(5, 3))
display_html(
df[:3].append(df[:2]),
df[:3].append([df[:2], df[2:]]),
)
In [4]:
df1 = pd.DataFrame(np.random.randn(3, 3), columns=['A', 'B', 'C'])
df2 = pd.DataFrame(np.random.randn(2, 3), columns=['A', 'B', 'C'])
display_html(
df1.append(df2, ignore_index=True),
df1.append(df2, ignore_index=False),
pd.concat([df1, df2], ignore_index=True),
pd.concat([df1, df2], ignore_index=False),
)
df = pd.DataFrame(np.random.randn(4, 2), columns=['A', 'B']) s = pd.Series(np.random.randn(4), name='S') display_html( pd.concat([df, s]), pd.concat([df, s], axis=1), )
In [5]:
df = pd.DataFrame(np.random.randn(3, 5), columns=['A', 'B', 'C', 'D', 'E'])
s = df.xs(1)
display_html(
df.append(s),
df.append([{'A': 1, 'B': 0, 'C': 3, 'E': 10, 'G': -11}])
)