The tools in this book are of little use if you can’t easily import and export data in Python. I’m going to be focused on input and output with pandas objects, though there are of course numerous tools in other libraries to aid in this process. NumPy, for example, features low-level but extremely fast binary data loading and storage, including support for memory-mapped array. See Chapter 12 for more on those.
Input and output typically falls into a few main categories: reading text files and other more efficient on-disk formats, loading data from databases, and interacting with network sources like web APIs.
Python has become a beloved language for text and file munging due to its simple syntax for interacting with files, intuitive data structures, and convenient features like tuple packing and unpacking.
pandas features a number of functions for reading tabular data as a
DataFrame object. Table 6-1 has a summary
of all of them, though
read_table are likely the
ones you’ll use the most.
Table 6-1. Parsing functions in pandas
|Load delimited data from a file, URL, or file-like object. Use comma as default delimiter|
|Load delimited data from a file, URL, or file-like object.
Use tab (|
|Read data in fixed-width column format (that is, no delimiters)|
|Version of |