Book Image

Learning Pandas

By : Michael Heydt
Book Image

Learning Pandas

By: Michael Heydt

Overview of this book

Table of Contents (19 chapters)
Learning pandas
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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 save the Excel data we just read in to a JSON file and then take a look at the contents:

In [25]:
   # write the excel data to a JSON file
   df.head().to_json("data/stocks.json")
   !cat data/stocks.json # osx or Linux
   # !type data\stocks.json # windows

   {"Date":{"0":1405900800000,"1":1405641600000,"2":1405555200000,"3":1405468800000,"4":1405382400000}, "Open":{"0":83.46,"1":83.3,"2":84.35,"3":83.77,"4":84.3}, "High":{"0":83.53,"1":83.4,"2":84.63,"3":84.91,"4":84.38}, "Low":{"0":81.81,"1":82.52,"2":83.33,"3":83.66,"4":83.2}, "Close":{"0":81.93,"1":83.35,"2":83.63,"3":84.91,"4":83.58},   "Volume":{"0":2359300,"1":4020800,"2":1974000,"3":1755600,"4":1874700}, 
"Adj Close":{"0":81.93,"1":83.35,"2":83.63,"3":84.91,"4":83...