How to do it

This is a very simple task to perform with pandas. The code of the example is in 08/03_visualize_wikipedia_edits.py.

  1. The code begins by importing pandas and matplotlib.pyplot:
>>> import pandas as pd>>> import matplotlib.pyplot as plt
  1. The data file we created in the previous recipe is already in a format that can be read directly by pandas. This is one of the benefits of using JSON as a data format; pandas has built-in support for reading and writing data from JSON. The following reads in the data using the pd.read_json() function and displays the first five rows on the console:
>>> df = pd.read_json("geo_ips.json")>>> df[:5])city country_code country_name ip latitude \0 Hanoi VN Vietnam 118.70.248.17 21.0333 1 Roskilde DK ...

Get Python Web Scraping 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.