I7MyX




Pay Notebook Creator: Jazmyn Fuller0
Set Container: Numerical CPU with TINY Memory for 10 Minutes 0
Total0

Merge Tables

If two tables have the same column, then we can merge them into a single table by matching rows.

Thanks to the National Centers for Environmental Information for collecting temperature and precipitation data by state.

{ a_table : Table 1 ? Table to Include in Merge }

{ b_table : Table 2 ? Table to Include in Merge }

{ key_column_name : Key Column ? Column to Use for Merge }

In [ ]:
# CrossCompute
a_table_path = 'usa-temperature-by-state.csv'
b_table_path = 'usa-precipitation-by-state.csv'
key_column_name = 'State'
target_folder = '/tmp'
In [ ]:
import pandas as pd
a_table = pd.read_csv(a_table_path)
b_table = pd.read_csv(b_table_path)
c_table = pd.merge(a_table, b_table, on=key_column_name)
In [ ]:
from os.path import join
target_path = join(target_folder, 'table.csv')
c_table.to_csv(target_path, index=False)
print('c_table_path = ' + target_path)

Merged Tables

{ c_table : Merged Table }