Example 1: concat columns pandas dataframe
In [1]: df1 = pd.DataFrame(
...: {
...: "A": ["A0", "A1", "A2", "A3"],
...: "B": ["B0", "B1", "B2", "B3"],
...: "C": ["C0", "C1", "C2", "C3"],
...: "D": ["D0", "D1", "D2", "D3"],
...: },
...: index=[0, 1, 2, 3],
...: )
In [8]: df4 = pd.DataFrame(
...: {
...: "B": ["B2", "B3", "B6", "B7"],
...: "D": ["D2", "D3", "D6", "D7"],
...: "F": ["F2", "F3", "F6", "F7"],
...: },
...: index=[2, 3, 6, 7],
...: )
...:
In [9]: result = pd.concat([df1, df4], axis=1)
Example 2: merge on row number python
pd.concat([T1,T2],axis=1)
Example 3: concat dataframe from list of dataframe
import pandas as pd
df = pd.concat(list_of_dataframes)
Example 4: Joins with another DataFrame
df.join(df2, df.name == df2.name, 'outer').select(
df.name, df2.height).collect()
df.join(df2, 'name', 'outer').select('name', 'height').collect()
cond = [df.name == df3.name, df.age == df3.age]
df.join(df3, cond, 'outer').select(df.name, df3.age).collect()
df.join(df2, 'name').select(df.name, df2.height).collect()
df.join(df4, ['name', 'age']).select(df.name, df.age).collect()
Example 5: how to merge two pandas dataframes on a column
import pandas as pd
T1 = pd.merge(T1, T2, on=T1.index, how='outer')
Example 6: merge two df
bigdata = pd.concat([data1, data2], ignore_index=True, sort=False)