Book Image

Learning pandas - Second Edition

By : Michael Heydt
Book Image

Learning pandas - Second Edition

By: Michael Heydt

Overview of this book

You will learn how to use pandas to perform data analysis in Python. You will start with an overview of data analysis and iteratively progress from modeling data, to accessing data from remote sources, performing numeric and statistical analysis, through indexing and performing aggregate analysis, and finally to visualizing statistical data and applying pandas to finance. With the knowledge you gain from this book, you will quickly learn pandas and how it can empower you in the exciting world of data manipulation, analysis and science.
Table of Contents (16 chapters)

Reading and writing JSON files

Pandas can read and write data stored in the JavaScript Object Notation (JSON) format. This is one of my favorites, due to its ability to be used across platforms and with many programming languages.

To demonstrate saving as JSON, we will first save the Excel data we just read into a JSON file and examine the contents:

JSON-based data can be read with the pd.read_json() function:

Note the two slight differences here, caused by the reading/writing of data from JSON. First, the columns have been reordered alphabetically. Second, the index for DataFrame, although containing content, is sorted as a string. These issues can be fixed easily, but they will not be covered here for brevity.