Python for Finance: Analyze Big Financial Data

(Elle) #1

I/O with pandas


One of the major strengths of the pandas library is that it can read and write different data


formats natively, including among others:


CSV (comma-separated value)


SQL (Structured Query Language)


XLS/XSLX (Microsoft Excel files)


JSON (JavaScript Object Notation)


HTML (HyperText Markup Language)


Table 7-1 lists all the supported formats and the corresponding import and export


functions/methods of pandas. The parameters that the import functions take are listed and


described in Table 6-6 (depending on the functions, some other conventions might apply).


Table 7-1. Parameters of DataFrame function


Format Input Output Remark

CSV

read_csv

to_csv

Text file

XLS/XLSX

read_excel

to_excel

Spreadsheet

HDF

read_hdf

to_hdf

HDF5 database

SQL

read_sql

to_sql

SQL table

JSON

read_json

to_json

JavaScript Object Notation

MSGPACK

read_msgpack

to_msgpack

Portable binary format

HTML

read_html

to_html

HTML code

GBQ

read_gbq

to_gbq

Google Big Query format

DTA

read_stata

to_stata

Formats 104, 105, 108, 113-115, 117

Any

read_clipboard

to_clipboard

E.g., from HTML page

Any

read_pickle

to_pickle

(Structured) Python object
Free download pdf