Merging two datasets in Pandas

In order to show a consolidated view of the data contained in two datasets, you need to merge them. Pandas has a built-in functionality to perform SQL-like joins of two DataFrames.

Getting ready

Create two DataFrames, one each from the accident and casualty datasets:

import pandas as pd accidents_data_file = 'Accidents7904.csv' casualty_data_file = 'Casualty7904.csv' af = base_file_path + accidents_data_file # Create a DataFrame from the accidents data accidents = pd.read_csv(af, sep=',', header=0, index_col=0, parse_dates=False, tupleize_cols=False, error_bad_lines=False, warn_bad_lines=False, skip_blank_lines=True, nrows=1000 ) # Create a DataFrame from the casualty data cf = base_file_path + casualty_data_file casualties ...

Get Python Business Intelligence Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.