Reshape DataFrame¶
In [9]:
import pandas as pd
import numpy as np
In [10]:
df1 = pd.DataFrame({"x": [1, 2, 3], "y": [5, 4, 3]})
df1
Out[10]:
In [3]:
df2 = pd.DataFrame({"x": [0, 0, 3000], "y": [78, 4, 3]})
df2
Out[3]:
Concate Rows¶
You can use both the DataFrame.append
(returns a new data frame rather than in-place) and pandas.concat
to concate rows of data frames.
pandas.concat
is recommended when you want to concate rows of multiple data frames.
In [4]:
df1.append(df2, ignore_index=True)
Out[4]:
In [5]:
df1
Out[5]:
In [6]:
pd.concat([df1, df2], ignore_index=True)
Out[6]:
Repeat rows of a DataFrame.
In [11]:
pd.concat([df1] * 3, ignore_index=True)
Out[11]:
Concate Columns¶
In [7]:
pd.concat([df1, df2], axis=1)
Out[7]:
In [8]:
pd.concat([df1, df2], ignore_index=True, axis=1)
Out[8]:
In [ ]: