{"id":133,"date":"2013-03-31T23:43:21","date_gmt":"2013-04-01T04:43:21","guid":{"rendered":"http:\/\/homepages.uc.edu\/~yaozo\/wordpress\/?p=133"},"modified":"2013-03-31T23:43:21","modified_gmt":"2013-04-01T04:43:21","slug":"io-tools-text-csv-hdf5","status":"publish","type":"post","link":"https:\/\/zhuoyao.net\/index.php\/2013\/03\/31\/io-tools-text-csv-hdf5\/","title":{"rendered":"IO Tools (Text, CSV, HDF5, &#8230;)"},"content":{"rendered":"<h2>CSV &amp; Text files<\/h2>\n<p>The two workhorse functions for reading text files (a.k.a. flat files) are<a title=\"pandas.io.parsers.read_csv\" href=\"http:\/\/pandas.pydata.org\/pandas-docs\/dev\/generated\/pandas.io.parsers.read_csv.html#pandas.io.parsers.read_csv\"><tt>read_csv()<\/tt><\/a>\u00a0and\u00a0<a title=\"pandas.io.parsers.read_table\" href=\"http:\/\/pandas.pydata.org\/pandas-docs\/dev\/generated\/pandas.io.parsers.read_table.html#pandas.io.parsers.read_table\"><tt>read_table()<\/tt><\/a>. They both use the same parsing code to intelligently convert tabular data into a DataFrame object. They can take a number of arguments:<\/p>\n<p>See some\u00a0<a href=\"http:\/\/pandas.pydata.org\/pandas-docs\/dev\/cookbook.html#cookbook-csv\"><em>cookbook examples<\/em><\/a>\u00a0for some advanced strategies See some<a href=\"http:\/\/pandas.pydata.org\/pandas-docs\/dev\/cookbook.html#cookbook-csv\"><em>cookbook examples<\/em><\/a>\u00a0for some advanced strategies<\/p>\n<blockquote>\n<ul>\n<li><tt>filepath_or_buffer<\/tt>: Either a string path to a file, or any object with a\u00a0<tt>read<\/tt>method (such as an open file or\u00a0<tt>StringIO<\/tt>).<\/li>\n<li><tt>sep<\/tt>\u00a0or\u00a0<tt>delimiter<\/tt>: A delimiter \/ separator to split fields on.\u00a0<cite>read_csv<\/cite>\u00a0is capable of inferring the delimiter automatically in some cases by \u201csniffing.\u201d The separator may be specified as a regular expression; for instance you may use \u2018|\\s*\u2019 to indicate a pipe plus arbitrary whitespace.<\/li>\n<li><tt>delim_whitespace<\/tt>: Parse whitespace-delimited (spaces or tabs) file (much faster than using a regular expression)<\/li>\n<li><tt>compression<\/tt>: decompress\u00a0<tt>'gzip'<\/tt>\u00a0and\u00a0<tt>'bz2'<\/tt>\u00a0formats on the fly.<\/li>\n<li><tt>dialect<\/tt>: string or\u00a0<a title=\"(in Python v2.7)\" href=\"http:\/\/docs.python.org\/library\/csv.html#csv.Dialect\"><tt>csv.Dialect<\/tt><\/a>\u00a0instance to expose more ways to specify the file format<\/li>\n<li><tt>dtype<\/tt>: A data type name or a dict of column name to data type. If not specified, data types will be inferred.<\/li>\n<li><tt>header<\/tt>: row number to use as the column names, and the start of the data. Defaults to 0 if no\u00a0<tt>names<\/tt>\u00a0passed, otherwise\u00a0<tt>None<\/tt>. Explicitly pass<tt>header=0<\/tt>\u00a0to be able to replace existing names.<\/li>\n<li><tt>skiprows<\/tt>: A collection of numbers for rows in the file to skip. Can also be an integer to skip the first\u00a0<tt>n<\/tt>\u00a0rows<\/li>\n<li><tt>index_col<\/tt>: column number, column name, or list of column numbers\/names, to use as the\u00a0<tt>index<\/tt>\u00a0(row labels) of the resulting DataFrame. By default, it will number the rows without using any column, unless there is one more data column than there are headers, in which case the first column is taken as the index.<\/li>\n<li><tt>names<\/tt>: List of column names to use as column names. To replace header existing in file, explicitly pass\u00a0<tt>header=0<\/tt>.<\/li>\n<li><tt>na_values<\/tt>: optional list of strings to recognize as NaN (missing values), either in addition to or in lieu of the default set.<\/li>\n<li><tt>true_values<\/tt>: list of strings to recognize as\u00a0<tt>True<\/tt><\/li>\n<li><tt>false_values<\/tt>: list of strings to recognize as\u00a0<tt>False<\/tt><\/li>\n<li><tt>keep_default_na<\/tt>: whether to include the default set of missing values in addition to the ones specified in\u00a0<tt>na_values<\/tt><\/li>\n<li><tt>parse_dates<\/tt>: if True then index will be parsed as dates (False by default). You can specify more complicated options to parse a subset of columns or a combination of columns into a single date column (list of ints or names, list of lists, or dict) [1, 2, 3] -&gt; try parsing columns 1, 2, 3 each as a separate date column [[1, 3]] -&gt; combine columns 1 and 3 and parse as a single date column {\u2018foo\u2019 : [1, 3]} -&gt; parse columns 1, 3 as date and call result \u2018foo\u2019<\/li>\n<li><tt>keep_date_col<\/tt>: if True, then date component columns passed into<tt>parse_dates<\/tt>\u00a0will be retained in the output (False by default).<\/li>\n<li><tt>date_parser<\/tt>: function to use to parse strings into datetime objects. If<tt>parse_dates<\/tt>\u00a0is True, it defaults to the very robust\u00a0<tt>dateutil.parser<\/tt>. Specifying this implicitly sets\u00a0<tt>parse_dates<\/tt>\u00a0as True. You can also use functions from community supported date converters from date_converters.py<\/li>\n<li><tt>dayfirst<\/tt>: if True then uses the DD\/MM international\/European date format (This is False by default)<\/li>\n<li><tt>thousands<\/tt>: sepcifies the thousands separator. If not None, then parser will try to look for it in the output and parse relevant data to integers. Because it has to essentially scan through the data again, this causes a significant performance hit so only use if necessary.<\/li>\n<li><tt>comment<\/tt>: denotes the start of a comment and ignores the rest of the line. Currently line commenting is not supported.<\/li>\n<li><tt>nrows<\/tt>: Number of rows to read out of the file. Useful to only read a small portion of a large file<\/li>\n<li><tt>iterator<\/tt>: If True, return a\u00a0<tt>TextParser<\/tt>\u00a0to enable reading a file into memory piece by piece<\/li>\n<li><tt>chunksize<\/tt>: An number of rows to be used to \u201cchunk\u201d a file into pieces. Will cause an\u00a0<tt>TextParser<\/tt>\u00a0object to be returned. More on this below in the section on\u00a0<a href=\"http:\/\/pandas.pydata.org\/pandas-docs\/dev\/io.html#io-chunking\"><em>iterating and chunking<\/em><\/a><\/li>\n<li><tt>skip_footer<\/tt>: number of lines to skip at bottom of file (default 0)<\/li>\n<li><tt>converters<\/tt>: a dictionary of functions for converting values in certain columns, where keys are either integers or column labels<\/li>\n<li><tt>encoding<\/tt>: a string representing the encoding to use for decoding unicode data, e.g.\u00a0<tt>'utf-8`<\/tt>\u00a0or\u00a0<tt>'latin-1'<\/tt>.<\/li>\n<li><tt>verbose<\/tt>: show number of NA values inserted in non-numeric columns<\/li>\n<li><tt>squeeze<\/tt>: if True then output with only one column is turned into Series<\/li>\n<li><tt>error_bad_lines<\/tt>: if False then any lines causing an error will be skipped<a href=\"http:\/\/pandas.pydata.org\/pandas-docs\/dev\/io.html#io-bad-lines\"><em>bad lines<\/em><\/a><\/li>\n<\/ul>\n<\/blockquote>\n<p>Consider a typical CSV file containing, in this case, some time series data:<\/p>\n<div>\n<div>\n<pre>In [1044]: print open('foo.csv').read()\ndate,A,B,C\n20090101,a,1,2\n20090102,b,3,4\n20090103,c,4,5<\/pre>\n<\/div>\n<\/div>\n<p>The default for\u00a0<cite>read_csv<\/cite>\u00a0is to create a DataFrame with simple numbered rows:<\/p>\n<div>\n<div>\n<pre>In [1045]: pd.read_csv('foo.csv')\nOut[1045]: \n       date  A  B  C\n0  20090101  a  1  2\n1  20090102  b  3  4\n2  20090103  c  4  5<\/pre>\n<\/div>\n<\/div>\n<p>In the case of indexed data, you can pass the column number or column name you wish to use as the index:<\/p>\n<div>\n<div>\n<pre>In [1046]: pd.read_csv('foo.csv', index_col=0)\nOut[1046]: \n          A  B  C\ndate             \n20090101  a  1  2\n20090102  b  3  4\n20090103  c  4  5<\/pre>\n<\/div>\n<\/div>\n<div>\n<div>\n<pre>In [1047]: pd.read_csv('foo.csv', index_col='date')\nOut[1047]: \n          A  B  C\ndate             \n20090101  a  1  2\n20090102  b  3  4\n20090103  c  4  5<\/pre>\n<\/div>\n<\/div>\n<p>You can also use a list of columns to create a hierarchical index:<\/p>\n<div>\n<div>\n<pre>In [1048]: pd.read_csv('foo.csv', index_col=[0, 'A'])\nOut[1048]: \n            B  C\ndate     A      \n20090101 a  1  2\n20090102 b  3  4\n20090103 c  4  5<\/pre>\n<\/div>\n<\/div>\n<p id=\"io-dialect\">The\u00a0<tt>dialect<\/tt>\u00a0keyword gives greater flexibility in specifying the file format. By default it uses the Excel dialect but you can specify either the dialect name or a\u00a0<a title=\"(in Python v2.7)\" href=\"http:\/\/docs.python.org\/library\/csv.html#csv.Dialect\"><tt>csv.Dialect<\/tt><\/a>\u00a0instance.<\/p>\n<p>Suppose you had data with unenclosed quotes:<\/p>\n<div>\n<div>\n<pre>In [1049]: print data\nlabel1,label2,label3\nindex1,\"a,c,e\nindex2,b,d,f<\/pre>\n<\/div>\n<\/div>\n<p>By default,\u00a0<tt>read_csv<\/tt>\u00a0uses the Excel dialect and treats the double quote as the quote character, which causes it to fail when it finds a newline before it finds the closing double quote.<\/p>\n<p>We can get around this using\u00a0<tt>dialect<\/tt><\/p>\n<div>\n<div>\n<pre>In [1050]: dia = csv.excel()\n\nIn [1051]: dia.quoting = csv.QUOTE_NONE\n\nIn [1052]: pd.read_csv(StringIO(data), dialect=dia)\nOut[1052]: \n       label1 label2 label3\nindex1     \"a      c      e\nindex2      b      d      f<\/pre>\n<\/div>\n<\/div>\n<p>All of the dialect options can be specified separately by keyword arguments:<\/p>\n<div>\n<div>\n<pre>In [1053]: data = 'a,b,c~1,2,3~4,5,6'\n\nIn [1054]: pd.read_csv(StringIO(data), lineterminator='~')\nOut[1054]: \n   a  b  c\n0  1  2  3\n1  4  5  6<\/pre>\n<\/div>\n<\/div>\n<p>Another common dialect option is\u00a0<tt>skipinitialspace<\/tt>, to skip any whitespace after a delimiter:<\/p>\n<div>\n<div>\n<pre>In [1055]: data = 'a, b, c\\n1, 2, 3\\n4, 5, 6'\n\nIn [1056]: print data\na, b, c\n1, 2, 3\n4, 5, 6\n\nIn [1057]: pd.read_csv(StringIO(data), skipinitialspace=True)\nOut[1057]: \n   a  b  c\n0  1  2  3\n1  4  5  6<\/pre>\n<\/div>\n<\/div>\n<p>The parsers make every attempt to \u201cdo the right thing\u201d and not be very fragile. Type inference is a pretty big deal. So if a column can be coerced to integer dtype without altering the contents, it will do so. Any non-numeric columns will come through as object dtype as with the rest of pandas objects.<\/p>\n<div id=\"specifying-column-data-types\">\n<h3>Specifying column data types<\/h3>\n<p>Starting with v0.10, you can indicate the data type for the whole DataFrame or individual columns:<\/p>\n<div>\n<div>\n<pre>In [1058]: data = 'a,b,c\\n1,2,3\\n4,5,6\\n7,8,9'\n\nIn [1059]: print data\na,b,c\n1,2,3\n4,5,6\n7,8,9\n\nIn [1060]: df = pd.read_csv(StringIO(data), dtype=object)\n\nIn [1061]: df\nOut[1061]: \n   a  b  c\n0  1  2  3\n1  4  5  6\n2  7  8  9\n\nIn [1062]: df['a'][0]\nOut[1062]: '1'\n\nIn [1063]: df = pd.read_csv(StringIO(data), dtype={'b': object, 'c': np.float64})\n\nIn [1064]: df.dtypes\nOut[1064]: \na      int64\nb     object\nc    float64\ndtype: object<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<div id=\"handling-column-names\">\n<h3>Handling column names<\/h3>\n<p>A file may or may not have a header row. pandas assumes the first row should be used as the column names:<\/p>\n<div>\n<div>\n<pre>In [1065]: from StringIO import StringIO\n\nIn [1066]: data = 'a,b,c\\n1,2,3\\n4,5,6\\n7,8,9'\n\nIn [1067]: print data\na,b,c\n1,2,3\n4,5,6\n7,8,9\n\nIn [1068]: pd.read_csv(StringIO(data))\nOut[1068]: \n   a  b  c\n0  1  2  3\n1  4  5  6\n2  7  8  9<\/pre>\n<\/div>\n<\/div>\n<p>By specifying the\u00a0<tt>names<\/tt>\u00a0argument in conjunction with\u00a0<tt>header<\/tt>\u00a0you can indicate other names to use and whether or not to throw away the header row (if any):<\/p>\n<div>\n<div>\n<pre>In [1069]: print data\na,b,c\n1,2,3\n4,5,6\n7,8,9\n\nIn [1070]: pd.read_csv(StringIO(data), names=['foo', 'bar', 'baz'], header=0)\nOut[1070]: \n   foo  bar  baz\n0    1    2    3\n1    4    5    6\n2    7    8    9\n\nIn [1071]: pd.read_csv(StringIO(data), names=['foo', 'bar', 'baz'], header=None)\nOut[1071]: \n  foo bar baz\n0   a   b   c\n1   1   2   3\n2   4   5   6\n3   7   8   9<\/pre>\n<\/div>\n<\/div>\n<p>If the header is in a row other than the first, pass the row number to\u00a0<tt>header<\/tt>. This will skip the preceding rows:<\/p>\n<div>\n<div>\n<pre>In [1072]: data = 'skip this skip it\\na,b,c\\n1,2,3\\n4,5,6\\n7,8,9'\n\nIn [1073]: pd.read_csv(StringIO(data), header=1)\nOut[1073]: \n   a  b  c\n0  1  2  3\n1  4  5  6\n2  7  8  9<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<div id=\"filtering-columns-usecols\">\n<h3>Filtering columns (<tt>usecols<\/tt>)<\/h3>\n<p>The\u00a0<tt>usecols<\/tt>\u00a0argument allows you to select any subset of the columns in a file, either using the column names or position numbers:<\/p>\n<div>\n<div>\n<pre>In [1074]: data = 'a,b,c,d\\n1,2,3,foo\\n4,5,6,bar\\n7,8,9,baz'\n\nIn [1075]: pd.read_csv(StringIO(data))\nOut[1075]: \n   a  b  c    d\n0  1  2  3  foo\n1  4  5  6  bar\n2  7  8  9  baz\n\nIn [1076]: pd.read_csv(StringIO(data), usecols=['b', 'd'])\nOut[1076]: \n   b    d\n0  2  foo\n1  5  bar\n2  8  baz\n\nIn [1077]: pd.read_csv(StringIO(data), usecols=[0, 2, 3])\nOut[1077]: \n   a  c    d\n0  1  3  foo\n1  4  6  bar\n2  7  9  baz<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<div id=\"dealing-with-unicode-data\">\n<h3>Dealing with Unicode Data<\/h3>\n<p>The\u00a0<tt>encoding<\/tt>\u00a0argument should be used for encoded unicode data, which will result in byte strings being decoded to unicode in the result:<\/p>\n<div>\n<div>\n<pre>In [1078]: data = 'word,length\\nTr\\xe4umen,7\\nGr\\xfc\\xdfe,5'\n\nIn [1079]: df = pd.read_csv(StringIO(data), encoding='latin-1')\n\nIn [1080]: df\nOut[1080]: \n      word  length\n0  Tr\u00e4umen       7\n1    Gr\u00fc\u00dfe       5\n\nIn [1081]: df['word'][1]\nOut[1081]: u'Gr\\xfc\\xdfe'<\/pre>\n<\/div>\n<\/div>\n<p>Some formats which encode all characters as multiple bytes, like UTF-16, won\u2019t parse correctly at all without specifying the encoding.<\/p>\n<\/div>\n<div id=\"index-columns-and-trailing-delimiters\">\n<h3>Index columns and trailing delimiters<\/h3>\n<p>If a file has one more column of data than the number of column names, the first column will be used as the DataFrame\u2019s row names:<\/p>\n<div>\n<div>\n<pre>In [1082]: data = 'a,b,c\\n4,apple,bat,5.7\\n8,orange,cow,10'\n\nIn [1083]: pd.read_csv(StringIO(data))\nOut[1083]: \n        a    b     c\n4   apple  bat   5.7\n8  orange  cow  10.0<\/pre>\n<\/div>\n<\/div>\n<div>\n<div>\n<pre>In [1084]: data = 'index,a,b,c\\n4,apple,bat,5.7\\n8,orange,cow,10'\n\nIn [1085]: pd.read_csv(StringIO(data), index_col=0)\nOut[1085]: \n            a    b     c\nindex                   \n4       apple  bat   5.7\n8      orange  cow  10.0<\/pre>\n<\/div>\n<\/div>\n<p>Ordinarily, you can achieve this behavior using the\u00a0<tt>index_col<\/tt>\u00a0option.<\/p>\n<p>There are some exception cases when a file has been prepared with delimiters at the end of each data line, confusing the parser. To explicitly disable the index column inference and discard the last column, pass\u00a0<tt>index_col=False<\/tt>:<\/p>\n<div>\n<div>\n<pre>In [1086]: data = 'a,b,c\\n4,apple,bat,\\n8,orange,cow,'\n\nIn [1087]: print data\na,b,c\n4,apple,bat,\n8,orange,cow,\n\nIn [1088]: pd.read_csv(StringIO(data))\nOut[1088]: \n        a    b   c\n4   apple  bat NaN\n8  orange  cow NaN\n\nIn [1089]: pd.read_csv(StringIO(data), index_col=False)\nOut[1089]: \n   a       b    c\n0  4   apple  bat\n1  8  orange  cow<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<div id=\"specifying-date-columns\">\n<h3>Specifying Date Columns<\/h3>\n<p>To better facilitate working with datetime data,\u00a0<a title=\"pandas.io.parsers.read_csv\" href=\"http:\/\/pandas.pydata.org\/pandas-docs\/dev\/generated\/pandas.io.parsers.read_csv.html#pandas.io.parsers.read_csv\"><tt>read_csv()<\/tt><\/a>\u00a0and\u00a0<a title=\"pandas.io.parsers.read_table\" href=\"http:\/\/pandas.pydata.org\/pandas-docs\/dev\/generated\/pandas.io.parsers.read_table.html#pandas.io.parsers.read_table\"><tt>read_table()<\/tt><\/a>\u00a0uses the keyword arguments\u00a0<tt>parse_dates<\/tt>\u00a0and\u00a0<tt>date_parser<\/tt>\u00a0to allow users to specify a variety of columns and date\/time formats to turn the input text data into\u00a0<tt>datetime<\/tt>\u00a0objects.<\/p>\n<p>The simplest case is to just pass in\u00a0<tt>parse_dates=True<\/tt>:<\/p>\n<div>\n<div>\n<pre># Use a column as an index, and parse it as dates.\nIn [1090]: df = pd.read_csv('foo.csv', index_col=0, parse_dates=True)\n\nIn [1091]: df\nOut[1091]: \n            A  B  C\ndate               \n2009-01-01  a  1  2\n2009-01-02  b  3  4\n2009-01-03  c  4  5\n\n# These are python datetime objects\nIn [1092]: df.index\nOut[1092]: \n&lt;class 'pandas.tseries.index.DatetimeIndex'&gt;\n[2009-01-01 00:00:00, ..., 2009-01-03 00:00:00]\nLength: 3, Freq: None, Timezone: None<\/pre>\n<\/div>\n<\/div>\n<p>It is often the case that we may want to store date and time data separately, or store various date fields separately. the\u00a0<tt>parse_dates<\/tt>\u00a0keyword can be used to specify a combination of columns to parse the dates and\/or times from.<\/p>\n<p>You can specify a list of column lists to\u00a0<tt>parse_dates<\/tt>, the resulting date columns will be prepended to the output (so as to not affect the existing column order) and the new column names will be the concatenation of the component column names:<\/p>\n<div>\n<div>\n<pre>In [1093]: print open('tmp.csv').read()\nKORD,19990127, 19:00:00, 18:56:00, 0.8100\nKORD,19990127, 20:00:00, 19:56:00, 0.0100\nKORD,19990127, 21:00:00, 20:56:00, -0.5900\nKORD,19990127, 21:00:00, 21:18:00, -0.9900\nKORD,19990127, 22:00:00, 21:56:00, -0.5900\nKORD,19990127, 23:00:00, 22:56:00, -0.5900\n\nIn [1094]: df = pd.read_csv('tmp.csv', header=None, parse_dates=[[1, 2], [1, 3]])\n\nIn [1095]: df\nOut[1095]: \n                  1_2                 1_3     0     4\n0 1999-01-27 19:00:00 1999-01-27 18:56:00  KORD  0.81\n1 1999-01-27 20:00:00 1999-01-27 19:56:00  KORD  0.01\n2 1999-01-27 21:00:00 1999-01-27 20:56:00  KORD -0.59\n3 1999-01-27 21:00:00 1999-01-27 21:18:00  KORD -0.99\n4 1999-01-27 22:00:00 1999-01-27 21:56:00  KORD -0.59\n5 1999-01-27 23:00:00 1999-01-27 22:56:00  KORD -0.59<\/pre>\n<\/div>\n<\/div>\n<p>By default the parser removes the component date columns, but you can choose to retain them via the\u00a0<tt>keep_date_col<\/tt>\u00a0keyword:<\/p>\n<div>\n<div>\n<pre>In [1096]: df = pd.read_csv('tmp.csv', header=None, parse_dates=[[1, 2], [1, 3]],\n   ......:                  keep_date_col=True)\n   ......:\n\nIn [1097]: df\nOut[1097]: \n                  1_2                 1_3     0         1          2          3     4\n0 1999-01-27 19:00:00 1999-01-27 18:56:00  KORD  19990127   19:00:00   18:56:00  0.81\n1 1999-01-27 20:00:00 1999-01-27 19:56:00  KORD  19990127   20:00:00   19:56:00  0.01\n2 1999-01-27 21:00:00 1999-01-27 20:56:00  KORD  19990127   21:00:00   20:56:00 -0.59\n3 1999-01-27 21:00:00 1999-01-27 21:18:00  KORD  19990127   21:00:00   21:18:00 -0.99\n4 1999-01-27 22:00:00 1999-01-27 21:56:00  KORD  19990127   22:00:00   21:56:00 -0.59\n5 1999-01-27 23:00:00 1999-01-27 22:56:00  KORD  19990127   23:00:00   22:56:00 -0.59<\/pre>\n<\/div>\n<\/div>\n<p>Note that if you wish to combine multiple columns into a single date column, a nested list must be used. In other words,\u00a0<tt>parse_dates=[1,\u00a02]<\/tt>\u00a0indicates that the second and third columns should each be parsed as separate date columns while\u00a0<tt>parse_dates=[[1,\u00a02]]<\/tt>\u00a0means the two columns should be parsed into a single column.<\/p>\n<p>You can also use a dict to specify custom name columns:<\/p>\n<div>\n<div>\n<pre>In [1098]: date_spec = {'nominal': [1, 2], 'actual': [1, 3]}\n\nIn [1099]: df = pd.read_csv('tmp.csv', header=None, parse_dates=date_spec)\n\nIn [1100]: df\nOut[1100]: \n              nominal              actual     0     4\n0 1999-01-27 19:00:00 1999-01-27 18:56:00  KORD  0.81\n1 1999-01-27 20:00:00 1999-01-27 19:56:00  KORD  0.01\n2 1999-01-27 21:00:00 1999-01-27 20:56:00  KORD -0.59\n3 1999-01-27 21:00:00 1999-01-27 21:18:00  KORD -0.99\n4 1999-01-27 22:00:00 1999-01-27 21:56:00  KORD -0.59\n5 1999-01-27 23:00:00 1999-01-27 22:56:00  KORD -0.59<\/pre>\n<\/div>\n<\/div>\n<p>It is important to remember that if multiple text columns are to be parsed into a single date column, then a new column is prepended to the data. The\u00a0<cite>index_col<\/cite>\u00a0specification is based off of this new set of columns rather than the original data columns:<\/p>\n<div>\n<div>\n<pre>In [1101]: date_spec = {'nominal': [1, 2], 'actual': [1, 3]}\n\nIn [1102]: df = pd.read_csv('tmp.csv', header=None, parse_dates=date_spec,\n   ......:                  index_col=0) #index is the nominal column\n   ......:\n\nIn [1103]: df\nOut[1103]: \n                                 actual     0     4\nnominal                                            \n1999-01-27 19:00:00 1999-01-27 18:56:00  KORD  0.81\n1999-01-27 20:00:00 1999-01-27 19:56:00  KORD  0.01\n1999-01-27 21:00:00 1999-01-27 20:56:00  KORD -0.59\n1999-01-27 21:00:00 1999-01-27 21:18:00  KORD -0.99\n1999-01-27 22:00:00 1999-01-27 21:56:00  KORD -0.59\n1999-01-27 23:00:00 1999-01-27 22:56:00  KORD -0.59<\/pre>\n<\/div>\n<\/div>\n<p><strong>Note<\/strong>: When passing a dict as the\u00a0<cite>parse_dates<\/cite>\u00a0argument, the order of the columns prepended is not guaranteed, because\u00a0<cite>dict<\/cite>\u00a0objects do not impose an ordering on their keys. On Python 2.7+ you may use\u00a0<cite>collections.OrderedDict<\/cite>\u00a0instead of a regular\u00a0<cite>dict<\/cite>\u00a0if this matters to you. Because of this, when using a dict for \u2018parse_dates\u2019 in conjunction with the<cite>index_col<\/cite>\u00a0argument, it\u2019s best to specify\u00a0<cite>index_col<\/cite>\u00a0as a column label rather then as an index on the resulting frame.<\/p>\n<\/div>\n<div id=\"date-parsing-functions\">\n<h3>Date Parsing Functions<\/h3>\n<p>Finally, the parser allows you can specify a custom\u00a0<tt>date_parser<\/tt>\u00a0function to take full advantage of the flexiblity of the date parsing API:<\/p>\n<div>\n<div>\n<pre>In [1104]: import pandas.io.date_converters as conv\n\nIn [1105]: df = pd.read_csv('tmp.csv', header=None, parse_dates=date_spec,\n   ......:                  date_parser=conv.parse_date_time)\n   ......:\n\nIn [1106]: df\nOut[1106]: \n              nominal              actual     0     4\n0 1999-01-27 19:00:00 1999-01-27 18:56:00  KORD  0.81\n1 1999-01-27 20:00:00 1999-01-27 19:56:00  KORD  0.01\n2 1999-01-27 21:00:00 1999-01-27 20:56:00  KORD -0.59\n3 1999-01-27 21:00:00 1999-01-27 21:18:00  KORD -0.99\n4 1999-01-27 22:00:00 1999-01-27 21:56:00  KORD -0.59\n5 1999-01-27 23:00:00 1999-01-27 22:56:00  KORD -0.59<\/pre>\n<\/div>\n<\/div>\n<p>You can explore the date parsing functionality in\u00a0<tt>date_converters.py<\/tt>\u00a0and add your own. We would love to turn this module into a community supported set of date\/time parsers. To get you started,\u00a0<tt>date_converters.py<\/tt>\u00a0contains functions to parse dual date and time columns, year\/month\/day columns, and year\/month\/day\/hour\/minute\/second columns. It also contains a\u00a0<tt>generic_parser<\/tt>\u00a0function so you can curry it with a function that deals with a single date rather than the entire array.<\/p>\n<\/div>\n<div id=\"international-date-formats\">\n<h3>International Date Formats<\/h3>\n<p>While US date formats tend to be MM\/DD\/YYYY, many international formats use DD\/MM\/YYYY instead. For convenience, a\u00a0<tt>dayfirst<\/tt>\u00a0keyword is provided:<\/p>\n<div>\n<div>\n<pre>In [1107]: print open('tmp.csv').read()\ndate,value,cat\n1\/6\/2000,5,a\n2\/6\/2000,10,b\n3\/6\/2000,15,c\n\nIn [1108]: pd.read_csv('tmp.csv', parse_dates=[0])\nOut[1108]: \n                 date  value cat\n0 2000-01-06 00:00:00      5   a\n1 2000-02-06 00:00:00     10   b\n2 2000-03-06 00:00:00     15   c\n\nIn [1109]: pd.read_csv('tmp.csv', dayfirst=True, parse_dates=[0])\nOut[1109]: \n                 date  value cat\n0 2000-06-01 00:00:00      5   a\n1 2000-06-02 00:00:00     10   b\n2 2000-06-03 00:00:00     15   c<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<div id=\"thousand-separators\">\n<h3>Thousand Separators<\/h3>\n<p>For large integers that have been written with a thousands separator, you can set the<tt>thousands<\/tt>\u00a0keyword to\u00a0<tt>True<\/tt>\u00a0so that integers will be parsed correctly:<\/p>\n<p>By default, integers with a thousands separator will be parsed as strings<\/p>\n<div>\n<div>\n<pre>In [1110]: print open('tmp.csv').read()\nID|level|category\nPatient1|123,000|x\nPatient2|23,000|y\nPatient3|1,234,018|z\n\nIn [1111]: df = pd.read_csv('tmp.csv', sep='|')\n\nIn [1112]: df\nOut[1112]: \n         ID      level category\n0  Patient1    123,000        x\n1  Patient2     23,000        y\n2  Patient3  1,234,018        z\n\nIn [1113]: df.level.dtype\nOut[1113]: dtype('object')<\/pre>\n<\/div>\n<\/div>\n<p>The\u00a0<tt>thousands<\/tt>\u00a0keyword allows integers to be parsed correctly<\/p>\n<div>\n<div>\n<pre>In [1114]: print open('tmp.csv').read()\nID|level|category\nPatient1|123,000|x\nPatient2|23,000|y\nPatient3|1,234,018|z\n\nIn [1115]: df = pd.read_csv('tmp.csv', sep='|', thousands=',')\n\nIn [1116]: df\nOut[1116]: \n         ID    level category\n0  Patient1   123000        x\n1  Patient2    23000        y\n2  Patient3  1234018        z\n\nIn [1117]: df.level.dtype\nOut[1117]: dtype('int64')<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<div id=\"comments\">\n<h3>Comments<\/h3>\n<p>Sometimes comments or meta data may be included in a file:<\/p>\n<div>\n<div>\n<pre>In [1118]: print open('tmp.csv').read()\nID,level,category\nPatient1,123000,x # really unpleasant\nPatient2,23000,y # wouldn't take his medicine\nPatient3,1234018,z # awesome<\/pre>\n<\/div>\n<\/div>\n<p>By default, the parse includes the comments in the output:<\/p>\n<div>\n<div>\n<pre>In [1119]: df = pd.read_csv('tmp.csv')\n\nIn [1120]: df\nOut[1120]: \n         ID    level                        category\n0  Patient1   123000           x # really unpleasant\n1  Patient2    23000  y # wouldn't take his medicine\n2  Patient3  1234018                     z # awesome<\/pre>\n<\/div>\n<\/div>\n<p>We can suppress the comments using the\u00a0<tt>comment<\/tt>\u00a0keyword:<\/p>\n<div>\n<div>\n<pre>In [1121]: df = pd.read_csv('tmp.csv', comment='#')\n\nIn [1122]: df\nOut[1122]: \n         ID    level category\n0  Patient1   123000       x \n1  Patient2    23000       y \n2  Patient3  1234018       z<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<div id=\"returning-series\">\n<h3>Returning Series<\/h3>\n<p>Using the\u00a0<tt>squeeze<\/tt>\u00a0keyword, the parser will return output with a single column as a\u00a0<tt>Series<\/tt>:<\/p>\n<div>\n<div>\n<pre>In [1123]: print open('tmp.csv').read()\nlevel\nPatient1,123000\nPatient2,23000\nPatient3,1234018\n\nIn [1124]: output =  pd.read_csv('tmp.csv', squeeze=True)\n\nIn [1125]: output\nOut[1125]: \nPatient1     123000\nPatient2      23000\nPatient3    1234018\nName: level, dtype: int64\n\nIn [1126]: type(output)\nOut[1126]: pandas.core.series.Series<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<div id=\"boolean-values\">\n<h3>Boolean values<\/h3>\n<p>The common values\u00a0<tt>True<\/tt>,\u00a0<tt>False<\/tt>,\u00a0<tt>TRUE<\/tt>, and\u00a0<tt>FALSE<\/tt>\u00a0are all recognized as boolean. Sometime you would want to recognize some other values as being boolean. To do this use the<tt>true_values<\/tt>\u00a0and\u00a0<tt>false_values<\/tt>\u00a0options:<\/p>\n<div>\n<div>\n<pre>In [1127]: data= 'a,b,c\\n1,Yes,2\\n3,No,4'\n\nIn [1128]: print data\na,b,c\n1,Yes,2\n3,No,4\n\nIn [1129]: pd.read_csv(StringIO(data))\nOut[1129]: \n   a    b  c\n0  1  Yes  2\n1  3   No  4\n\nIn [1130]: pd.read_csv(StringIO(data), true_values=['Yes'], false_values=['No'])\nOut[1130]: \n   a      b  c\n0  1   True  2\n1  3  False  4<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<div id=\"handling-bad-lines\">\n<h3>Handling \u201cbad\u201d lines<\/h3>\n<p>Some files may have malformed lines with too few fields or too many. Lines with too few fields will have NA values filled in the trailing fields. Lines with too many will cause an error by default:<\/p>\n<div>\n<div>\n<pre>In [27]: data = 'a,b,c\\n1,2,3\\n4,5,6,7\\n8,9,10'\n\nIn [28]: pd.read_csv(StringIO(data))\n---------------------------------------------------------------------------\nCParserError                              Traceback (most recent call last)\nCParserError: Error tokenizing data. C error: Expected 3 fields in line 3, saw 4<\/pre>\n<\/div>\n<\/div>\n<p>You can elect to skip bad lines:<\/p>\n<div>\n<div>\n<pre>In [29]: pd.read_csv(StringIO(data), error_bad_lines=False)\nSkipping line 3: expected 3 fields, saw 4\n\nOut[29]:\n   a  b   c\n0  1  2   3\n1  8  9  10<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<div id=\"quoting-and-escape-characters\">\n<h3>Quoting and Escape Characters<\/h3>\n<p>Quotes (and other escape characters) in embedded fields can be handled in any number of ways. One way is to use backslashes; to properly parse this data, you should pass the<tt>escapechar<\/tt>\u00a0option:<\/p>\n<div>\n<div>\n<pre>In [1131]: data = 'a,b\\n\"hello, \\\\\"Bob\\\\\", nice to see you\",5'\n\nIn [1132]: print data\na,b\n\"hello, \\\"Bob\\\", nice to see you\",5\n\nIn [1133]: pd.read_csv(StringIO(data), escapechar='\\\\')\nOut[1133]: \n                               a  b\n0  hello, \"Bob\", nice to see you  5<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<div id=\"files-with-fixed-width-columns\">\n<h3>Files with Fixed Width Columns<\/h3>\n<p>While\u00a0<cite>read_csv<\/cite>\u00a0reads delimited data, the\u00a0<tt>read_fwf()<\/tt>\u00a0function works with data files that have known and fixed column widths. The function parameters to\u00a0<cite>read_fwf<\/cite>\u00a0are largely the same as\u00a0<cite>read_csv<\/cite>\u00a0with two extra parameters:<\/p>\n<blockquote>\n<ul>\n<li><tt>colspecs<\/tt>: a list of pairs (tuples), giving the extents of the fixed-width fields of each line as half-open intervals [from, to[<\/li>\n<li><tt>widths<\/tt>: a list of field widths, which can be used instead of\u00a0<tt>colspecs<\/tt>\u00a0if the intervals are contiguous<\/li>\n<\/ul>\n<\/blockquote>\n<p>Consider a typical fixed-width data file:<\/p>\n<div>\n<div>\n<pre>In [1134]: print open('bar.csv').read()\nid8141    360.242940   149.910199   11950.7\nid1594    444.953632   166.985655   11788.4\nid1849    364.136849   183.628767   11806.2\nid1230    413.836124   184.375703   11916.8\nid1948    502.953953   173.237159   12468.3<\/pre>\n<\/div>\n<\/div>\n<p>In order to parse this file into a DataFrame, we simply need to supply the column specifications to the\u00a0<cite>read_fwf<\/cite>\u00a0function along with the file name:<\/p>\n<div>\n<div>\n<pre>#Column specifications are a list of half-intervals\nIn [1135]: colspecs = [(0, 6), (8, 20), (21, 33), (34, 43)]\n\nIn [1136]: df = pd.read_fwf('bar.csv', colspecs=colspecs, header=None, index_col=0)\n\nIn [1137]: df\nOut[1137]: \n                 1           2        3\n0                                      \nid8141  360.242940  149.910199  11950.7\nid1594  444.953632  166.985655  11788.4\nid1849  364.136849  183.628767  11806.2\nid1230  413.836124  184.375703  11916.8\nid1948  502.953953  173.237159  12468.3<\/pre>\n<\/div>\n<\/div>\n<p>Note how the parser automatically picks column names X.&lt;column number&gt; when<tt>header=None<\/tt>\u00a0argument is specified. Alternatively, you can supply just the column widths for contiguous columns:<\/p>\n<div>\n<div>\n<pre>#Widths are a list of integers\nIn [1138]: widths = [6, 14, 13, 10]\n\nIn [1139]: df = pd.read_fwf('bar.csv', widths=widths, header=None)\n\nIn [1140]: df\nOut[1140]: \n        0           1           2        3\n0  id8141  360.242940  149.910199  11950.7\n1  id1594  444.953632  166.985655  11788.4\n2  id1849  364.136849  183.628767  11806.2\n3  id1230  413.836124  184.375703  11916.8\n4  id1948  502.953953  173.237159  12468.3<\/pre>\n<\/div>\n<\/div>\n<p>The parser will take care of extra white spaces around the columns so it\u2019s ok to have extra separation between the columns in the file.<\/p>\n<\/div>\n<div id=\"files-with-an-implicit-index-column\">\n<h3>Files with an \u201cimplicit\u201d index column<\/h3>\n<p>Consider a file with one less entry in the header than the number of data column:<\/p>\n<div>\n<div>\n<pre>In [1141]: print open('foo.csv').read()\nA,B,C\n20090101,a,1,2\n20090102,b,3,4\n20090103,c,4,5<\/pre>\n<\/div>\n<\/div>\n<p>In this special case,\u00a0<tt>read_csv<\/tt>\u00a0assumes that the first column is to be used as the index of the DataFrame:<\/p>\n<div>\n<div>\n<pre>In [1142]: pd.read_csv('foo.csv')\nOut[1142]: \n          A  B  C\n20090101  a  1  2\n20090102  b  3  4\n20090103  c  4  5<\/pre>\n<\/div>\n<\/div>\n<p>Note that the dates weren\u2019t automatically parsed. In that case you would need to do as before:<\/p>\n<div>\n<div>\n<pre>In [1143]: df = pd.read_csv('foo.csv', parse_dates=True)\n\nIn [1144]: df.index\nOut[1144]: \n&lt;class 'pandas.tseries.index.DatetimeIndex'&gt;\n[2009-01-01 00:00:00, ..., 2009-01-03 00:00:00]\nLength: 3, Freq: None, Timezone: None<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<div id=\"reading-dataframe-objects-with-multiindex\">\n<h3>Reading DataFrame objects with\u00a0<tt>MultiIndex<\/tt><\/h3>\n<p id=\"io-csv-multiindex\">Suppose you have data indexed by two columns:<\/p>\n<div>\n<div>\n<pre>In [1145]: print open('data\/mindex_ex.csv').read()\nyear,indiv,zit,xit\n1977,\"A\",1.2,.6\n1977,\"B\",1.5,.5\n1977,\"C\",1.7,.8\n1978,\"A\",.2,.06\n1978,\"B\",.7,.2\n1978,\"C\",.8,.3\n1978,\"D\",.9,.5\n1978,\"E\",1.4,.9\n1979,\"C\",.2,.15\n1979,\"D\",.14,.05\n1979,\"E\",.5,.15\n1979,\"F\",1.2,.5\n1979,\"G\",3.4,1.9\n1979,\"H\",5.4,2.7\n1979,\"I\",6.4,1.2<\/pre>\n<\/div>\n<\/div>\n<p>The\u00a0<tt>index_col<\/tt>\u00a0argument to\u00a0<tt>read_csv<\/tt>\u00a0and\u00a0<tt>read_table<\/tt>\u00a0can take a list of column numbers to turn multiple columns into a\u00a0<tt>MultiIndex<\/tt>:<\/p>\n<div>\n<div>\n<pre>In [1146]: df = pd.read_csv(\"data\/mindex_ex.csv\", index_col=[0,1])\n\nIn [1147]: df\nOut[1147]: \n             zit   xit\nyear indiv            \n1977 A      1.20  0.60\n     B      1.50  0.50\n     C      1.70  0.80\n1978 A      0.20  0.06\n     B      0.70  0.20\n     C      0.80  0.30\n     D      0.90  0.50\n     E      1.40  0.90\n1979 C      0.20  0.15\n     D      0.14  0.05\n     E      0.50  0.15\n     F      1.20  0.50\n     G      3.40  1.90\n     H      5.40  2.70\n     I      6.40  1.20\n\nIn [1148]: df.ix[1978]\nOut[1148]: \n       zit   xit\nindiv           \nA      0.2  0.06\nB      0.7  0.20\nC      0.8  0.30\nD      0.9  0.50\nE      1.4  0.90<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<div id=\"automatically-sniffing-the-delimiter\">\n<h3>Automatically \u201csniffing\u201d the delimiter<\/h3>\n<p><tt>read_csv<\/tt>\u00a0is capable of inferring delimited (not necessarily comma-separated) files. YMMV, as pandas uses the\u00a0<a title=\"(in Python v2.7)\" href=\"http:\/\/docs.python.org\/library\/csv.html#csv.Sniffer\"><tt>csv.Sniffer<\/tt><\/a>\u00a0class of the csv module.<\/p>\n<div>\n<div>\n<pre>In [1149]: print open('tmp2.sv').read()\n:0:1:2:3\n0:0.4691122999071863:-0.2828633443286633:-1.5090585031735124:-1.1356323710171934\n1:1.2121120250208506:-0.17321464905330858:0.11920871129693428:-1.0442359662799567\n2:-0.8618489633477999:-2.1045692188948086:-0.4949292740687813:1.071803807037338\n3:0.7215551622443669:-0.7067711336300845:-1.0395749851146963:0.27185988554282986\n4:-0.42497232978883753:0.567020349793672:0.27623201927771873:-1.0874006912859915\n5:-0.6736897080883706:0.1136484096888855:-1.4784265524372235:0.5249876671147047\n6:0.4047052186802365:0.5770459859204836:-1.7150020161146375:-1.0392684835147725\n7:-0.3706468582364464:-1.1578922506419993:-1.344311812731667:0.8448851414248841\n8:1.0757697837155533:-0.10904997528022223:1.6435630703622064:-1.4693879595399115\n9:0.35702056413309086:-0.6746001037299882:-1.776903716971867:-0.9689138124473498\n\nIn [1150]: pd.read_csv('tmp2.sv')\nOut[1150]: \n                                            :0:1:2:3\n0  0:0.4691122999071863:-0.2828633443286633:-1.50...\n1  1:1.2121120250208506:-0.17321464905330858:0.11...\n2  2:-0.8618489633477999:-2.1045692188948086:-0.4...\n3  3:0.7215551622443669:-0.7067711336300845:-1.03...\n4  4:-0.42497232978883753:0.567020349793672:0.276...\n5  5:-0.6736897080883706:0.1136484096888855:-1.47...\n6  6:0.4047052186802365:0.5770459859204836:-1.715...\n7  7:-0.3706468582364464:-1.1578922506419993:-1.3...\n8  8:1.0757697837155533:-0.10904997528022223:1.64...\n9  9:0.35702056413309086:-0.6746001037299882:-1.7...<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<div id=\"iterating-through-files-chunk-by-chunk\">\n<h3>Iterating through files chunk by chunk<\/h3>\n<p>Suppose you wish to iterate through a (potentially very large) file lazily rather than reading the entire file into memory, such as the following:<\/p>\n<div>\n<div>\n<pre>In [1151]: print open('tmp.sv').read()\n|0|1|2|3\n0|0.4691122999071863|-0.2828633443286633|-1.5090585031735124|-1.1356323710171934\n1|1.2121120250208506|-0.17321464905330858|0.11920871129693428|-1.0442359662799567\n2|-0.8618489633477999|-2.1045692188948086|-0.4949292740687813|1.071803807037338\n3|0.7215551622443669|-0.7067711336300845|-1.0395749851146963|0.27185988554282986\n4|-0.42497232978883753|0.567020349793672|0.27623201927771873|-1.0874006912859915\n5|-0.6736897080883706|0.1136484096888855|-1.4784265524372235|0.5249876671147047\n6|0.4047052186802365|0.5770459859204836|-1.7150020161146375|-1.0392684835147725\n7|-0.3706468582364464|-1.1578922506419993|-1.344311812731667|0.8448851414248841\n8|1.0757697837155533|-0.10904997528022223|1.6435630703622064|-1.4693879595399115\n9|0.35702056413309086|-0.6746001037299882|-1.776903716971867|-0.9689138124473498\n\nIn [1152]: table = pd.read_table('tmp.sv', sep='|')\n\nIn [1153]: table\nOut[1153]: \n   Unnamed: 0         0         1         2         3\n0           0  0.469112 -0.282863 -1.509059 -1.135632\n1           1  1.212112 -0.173215  0.119209 -1.044236\n2           2 -0.861849 -2.104569 -0.494929  1.071804\n3           3  0.721555 -0.706771 -1.039575  0.271860\n4           4 -0.424972  0.567020  0.276232 -1.087401\n5           5 -0.673690  0.113648 -1.478427  0.524988\n6           6  0.404705  0.577046 -1.715002 -1.039268\n7           7 -0.370647 -1.157892 -1.344312  0.844885\n8           8  1.075770 -0.109050  1.643563 -1.469388\n9           9  0.357021 -0.674600 -1.776904 -0.968914<\/pre>\n<\/div>\n<\/div>\n<p>By specifiying a\u00a0<tt>chunksize<\/tt>\u00a0to\u00a0<tt>read_csv<\/tt>\u00a0or\u00a0<tt>read_table<\/tt>, the return value will be an iterable object of type\u00a0<tt>TextParser<\/tt>:<\/p>\n<div>\n<div>\n<pre>In [1154]: reader = pd.read_table('tmp.sv', sep='|', chunksize=4)\n\nIn [1155]: reader\nOut[1155]: &lt;pandas.io.parsers.TextFileReader at 0xcc03b50&gt;\n\nIn [1156]: for chunk in reader:\n   ......:     print chunk\n   ......:\n   Unnamed: 0         0         1         2         3\n0           0  0.469112 -0.282863 -1.509059 -1.135632\n1           1  1.212112 -0.173215  0.119209 -1.044236\n2           2 -0.861849 -2.104569 -0.494929  1.071804\n3           3  0.721555 -0.706771 -1.039575  0.271860\n   Unnamed: 0         0         1         2         3\n0           4 -0.424972  0.567020  0.276232 -1.087401\n1           5 -0.673690  0.113648 -1.478427  0.524988\n2           6  0.404705  0.577046 -1.715002 -1.039268\n3           7 -0.370647 -1.157892 -1.344312  0.844885\n   Unnamed: 0         0        1         2         3\n0           8  1.075770 -0.10905  1.643563 -1.469388\n1           9  0.357021 -0.67460 -1.776904 -0.968914<\/pre>\n<\/div>\n<\/div>\n<p>Specifying\u00a0<tt>iterator=True<\/tt>\u00a0will also return the\u00a0<tt>TextParser<\/tt>\u00a0object:<\/p>\n<div>\n<div>\n<pre>In [1157]: reader = pd.read_table('tmp.sv', sep='|', iterator=True)\n\nIn [1158]: reader.get_chunk(5)\nOut[1158]: \n   Unnamed: 0         0         1         2         3\n0           0  0.469112 -0.282863 -1.509059 -1.135632\n1           1  1.212112 -0.173215  0.119209 -1.044236\n2           2 -0.861849 -2.104569 -0.494929  1.071804\n3           3  0.721555 -0.706771 -1.039575  0.271860\n4           4 -0.424972  0.567020  0.276232 -1.087401<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<div id=\"writing-to-csv-format\">\n<h3>Writing to CSV format<\/h3>\n<p id=\"io-store-in-csv\">The Series and DataFrame objects have an instance method\u00a0<tt>to_csv<\/tt>\u00a0which allows storing the contents of the object as a comma-separated-values file. The function takes a number of arguments. Only the first is required.<\/p>\n<blockquote>\n<ul>\n<li><tt>path<\/tt>: A string path to the file to write<\/li>\n<li><tt>nanRep<\/tt>: A string representation of a missing value (default \u2018\u2019)<\/li>\n<li><tt>cols<\/tt>: Columns to write (default None)<\/li>\n<li><tt>header<\/tt>: Whether to write out the column names (default True)<\/li>\n<li><tt>index<\/tt>: whether to write row (index) names (default True)<\/li>\n<li><tt>index_label<\/tt>: Column label(s) for index column(s) if desired. If None (default), and<cite>header<\/cite>\u00a0and\u00a0<cite>index<\/cite>\u00a0are True, then the index names are used. (A sequence should be given if the DataFrame uses MultiIndex).<\/li>\n<li><tt>mode<\/tt>\u00a0: Python write mode, default \u2018w\u2019<\/li>\n<li><tt>sep<\/tt>\u00a0: Field delimiter for the output file (default \u201d,\u201d)<\/li>\n<li><tt>encoding<\/tt>: a string representing the encoding to use if the contents are non-ascii, for python versions prior to 3<\/li>\n<\/ul>\n<\/blockquote>\n<\/div>\n<div id=\"writing-a-formatted-string\">\n<h3>Writing a formatted string<\/h3>\n<p id=\"io-formatting\">The DataFrame object has an instance method\u00a0<tt>to_string<\/tt>\u00a0which allows control over the string representation of the object. All arguments are optional:<\/p>\n<blockquote>\n<ul>\n<li><tt>buf<\/tt>\u00a0default None, for example a StringIO object<\/li>\n<li><tt>columns<\/tt>\u00a0default None, which columns to write<\/li>\n<li><tt>col_space<\/tt>\u00a0default None, minimum width of each column.<\/li>\n<li><tt>na_rep<\/tt>\u00a0default\u00a0<tt>NaN<\/tt>, representation of NA value<\/li>\n<li><tt>formatters<\/tt>\u00a0default None, a dictionary (by column) of functions each of which takes a single argument and returns a formatted string<\/li>\n<li><tt>float_format<\/tt>\u00a0default None, a function which takes a single (float) argument and returns a formatted string; to be applied to floats in the DataFrame.<\/li>\n<li><tt>sparsify<\/tt>\u00a0default True, set to False for a DataFrame with a hierarchical index to print every multiindex key at each row.<\/li>\n<li><tt>index_names<\/tt>\u00a0default True, will print the names of the indices<\/li>\n<li><tt>index<\/tt>\u00a0default True, will print the index (ie, row labels)<\/li>\n<li><tt>header<\/tt>\u00a0default True, will print the column labels<\/li>\n<li><tt>justify<\/tt>\u00a0default\u00a0<tt>left<\/tt>, will print column headers left- or right-justified<\/li>\n<\/ul>\n<\/blockquote>\n<p>The Series object also has a\u00a0<tt>to_string<\/tt>\u00a0method, but with only the\u00a0<tt>buf<\/tt>,\u00a0<tt>na_rep<\/tt>,\u00a0<tt>float_format<\/tt>arguments. There is also a\u00a0<tt>length<\/tt>\u00a0argument which, if set to\u00a0<tt>True<\/tt>, will additionally output the length of the Series.<\/p>\n<\/div>\n<div id=\"writing-to-html-format\">\n<h3>Writing to HTML format<\/h3>\n<p id=\"io-html\">DataFrame object has an instance method\u00a0<tt>to_html<\/tt>\u00a0which renders the contents of the DataFrame as an html table. The function arguments are as in the method\u00a0<tt>to_string<\/tt>described above.<\/p>\n<\/div>\n<div id=\"clipboard\">\n<h2>Clipboard<\/h2>\n<p id=\"io-clipboard\">A handy way to grab data is to use the\u00a0<tt>read_clipboard<\/tt>\u00a0method, which takes the contents of the clipboard buffer and passes them to the\u00a0<tt>read_table<\/tt>\u00a0method described in the next section. For instance, you can copy the following text to the clipboard (CTRL-C on many operating systems):<\/p>\n<div>\n<pre>  A B C\nx 1 4 p\ny 2 5 q\nz 3 6 r<\/pre>\n<\/div>\n<p>And then import the data directly to a DataFrame by calling:<\/p>\n<div>\n<div>\n<pre>clipdf = pd.read_clipboard(delim_whitespace=True)<\/pre>\n<\/div>\n<\/div>\n<div>\n<div>\n<pre>In [1159]: clipdf\nOut[1159]: \n   A  B  C\nx  1  4  p\ny  2  5  q\nz  3  6  r<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<div id=\"excel-files\">\n<h2>Excel files<\/h2>\n<p>The\u00a0<tt>ExcelFile<\/tt>\u00a0class can read an Excel 2003 file using the\u00a0<tt>xlrd<\/tt>\u00a0Python module and use the same parsing code as the above to convert tabular data into a DataFrame. To use it, create the\u00a0<tt>ExcelFile<\/tt>\u00a0object:<\/p>\n<p>See some\u00a0<a href=\"http:\/\/pandas.pydata.org\/pandas-docs\/dev\/cookbook.html#cookbook-excel\"><em>cookbook examples<\/em><\/a>\u00a0for some advanced strategies<\/p>\n<div>\n<div>\n<pre>xls = ExcelFile('path_to_file.xls')<\/pre>\n<\/div>\n<\/div>\n<p>Then use the\u00a0<tt>parse<\/tt>\u00a0instance method with a sheetname, then use the same additional arguments as the parsers above:<\/p>\n<div>\n<div>\n<pre>xls.parse('Sheet1', index_col=None, na_values=['NA'])<\/pre>\n<\/div>\n<\/div>\n<p>To read sheets from an Excel 2007 file, you can pass a filename with a\u00a0<tt>.xlsx<\/tt>\u00a0extension, in which case the\u00a0<tt>openpyxl<\/tt>\u00a0module will be used to read the file.<\/p>\n<p>It is often the case that users will insert columns to do temporary computations in Excel and you may not want to read in those columns.\u00a0<cite>ExcelFile.parse<\/cite>\u00a0takes a\u00a0<cite>parse_cols<\/cite>\u00a0keyword to allow you to specify a subset of columns to parse.<\/p>\n<p>If\u00a0<cite>parse_cols<\/cite>\u00a0is an integer, then it is assumed to indicate the last column to be parsed.<\/p>\n<div>\n<div>\n<pre>xls.parse('Sheet1', parse_cols=2, index_col=None, na_values=['NA'])<\/pre>\n<\/div>\n<\/div>\n<p>If\u00a0<cite>parse_cols<\/cite>\u00a0is a list of integers, then it is assumed to be the file column indices to be parsed.<\/p>\n<div>\n<div>\n<pre>xls.parse('Sheet1', parse_cols=[0, 2, 3], index_col=None, na_values=['NA'])<\/pre>\n<\/div>\n<\/div>\n<p>To write a DataFrame object to a sheet of an Excel file, you can use the\u00a0<tt>to_excel<\/tt>\u00a0instance method. The arguments are largely the same as\u00a0<tt>to_csv<\/tt>\u00a0described above, the first argument being the name of the excel file, and the optional second argument the name of the sheet to which the DataFrame should be written. For example:<\/p>\n<div>\n<div>\n<pre>df.to_excel('path_to_file.xlsx', sheet_name='sheet1')<\/pre>\n<\/div>\n<\/div>\n<p>Files with a\u00a0<tt>.xls<\/tt>\u00a0extension will be written using\u00a0<tt>xlwt<\/tt>\u00a0and those with a\u00a0<tt>.xlsx<\/tt>\u00a0extension will be written using\u00a0<tt>openpyxl<\/tt>. The Panel class also has a\u00a0<tt>to_excel<\/tt>\u00a0instance method, which writes each DataFrame in the Panel to a separate sheet.<\/p>\n<p>In order to write separate DataFrames to separate sheets in a single Excel file, one can use the ExcelWriter class, as in the following example:<\/p>\n<div>\n<div>\n<pre>writer = ExcelWriter('path_to_file.xlsx')\ndf1.to_excel(writer, sheet_name='sheet1')\ndf2.to_excel(writer, sheet_name='sheet2')\nwriter.save()<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<div id=\"hdf5-pytables\">\n<h2>HDF5 (PyTables)<\/h2>\n<p><tt>HDFStore<\/tt>\u00a0is a dict-like object which reads and writes pandas using the high performance HDF5 format using the excellent\u00a0<a href=\"http:\/\/www.pytables.org\/\">PyTables<\/a>\u00a0library.<\/p>\n<p>See some\u00a0<a href=\"http:\/\/pandas.pydata.org\/pandas-docs\/dev\/cookbook.html#cookbook-hdf\"><em>cookbook examples<\/em><\/a>\u00a0for some advanced strategies<\/p>\n<div>\n<div>\n<pre>In [1160]: store = HDFStore('store.h5')\n\nIn [1161]: print store\n&lt;class 'pandas.io.pytables.HDFStore'&gt;\nFile path: store.h5\nEmpty<\/pre>\n<\/div>\n<\/div>\n<p>Objects can be written to the file just like adding key-value pairs to a dict:<\/p>\n<div>\n<div>\n<pre>In [1162]: index = date_range('1\/1\/2000', periods=8)\n\nIn [1163]: s = Series(randn(5), index=['a', 'b', 'c', 'd', 'e'])\n\nIn [1164]: df = DataFrame(randn(8, 3), index=index,\n   ......:                columns=['A', 'B', 'C'])\n   ......:\n\nIn [1165]: wp = Panel(randn(2, 5, 4), items=['Item1', 'Item2'],\n   ......:            major_axis=date_range('1\/1\/2000', periods=5),\n   ......:            minor_axis=['A', 'B', 'C', 'D'])\n   ......:\n\n# store.put('s', s) is an equivalent method\nIn [1166]: store['s'] = s\n\nIn [1167]: store['df'] = df\n\nIn [1168]: store['wp'] = wp\n\n# the type of stored data\nIn [1169]: store.root.wp._v_attrs.pandas_type\nOut[1169]: 'wide'\n\nIn [1170]: store\nOut[1170]: \n&lt;class 'pandas.io.pytables.HDFStore'&gt;\nFile path: store.h5\n\/df            frame        (shape-&gt;[8,3])  \n\/s             series       (shape-&gt;[5])    \n\/wp            wide         (shape-&gt;[2,5,4])<\/pre>\n<\/div>\n<\/div>\n<p>In a current or later Python session, you can retrieve stored objects:<\/p>\n<div>\n<div>\n<pre># store.get('df') is an equivalent method\nIn [1171]: store['df']\nOut[1171]: \n                   A         B         C\n2000-01-01 -0.362543 -0.006154 -0.923061\n2000-01-02  0.895717  0.805244 -1.206412\n2000-01-03  2.565646  1.431256  1.340309\n2000-01-04 -1.170299 -0.226169  0.410835\n2000-01-05  0.813850  0.132003 -0.827317\n2000-01-06 -0.076467 -1.187678  1.130127\n2000-01-07 -1.436737 -1.413681  1.607920\n2000-01-08  1.024180  0.569605  0.875906\n\n# dotted (attribute) access provides get as well\nIn [1172]: store.df\nOut[1172]: \n                   A         B         C\n2000-01-01 -0.362543 -0.006154 -0.923061\n2000-01-02  0.895717  0.805244 -1.206412\n2000-01-03  2.565646  1.431256  1.340309\n2000-01-04 -1.170299 -0.226169  0.410835\n2000-01-05  0.813850  0.132003 -0.827317\n2000-01-06 -0.076467 -1.187678  1.130127\n2000-01-07 -1.436737 -1.413681  1.607920\n2000-01-08  1.024180  0.569605  0.875906<\/pre>\n<\/div>\n<\/div>\n<p>Deletion of the object specified by the key<\/p>\n<div>\n<div>\n<pre># store.remove('wp') is an equivalent method\nIn [1173]: del store['wp']\n\nIn [1174]: store\nOut[1174]: \n&lt;class 'pandas.io.pytables.HDFStore'&gt;\nFile path: store.h5\n\/df            frame        (shape-&gt;[8,3])\n\/s             series       (shape-&gt;[5])<\/pre>\n<\/div>\n<\/div>\n<p>Closing a Store<\/p>\n<div>\n<div>\n<pre># closing a store\nIn [1175]: store.close()\n\n# Working with, and automatically closing the store with the context\n# manager\nIn [1176]: with get_store('store.h5') as store:\n   ......:      store.keys()\n   ......:<\/pre>\n<\/div>\n<\/div>\n<p>These stores are\u00a0<strong>not<\/strong>\u00a0appendable once written (though you can simply remove them and rewrite). Nor are they\u00a0<strong>queryable<\/strong>; they must be retrieved in their entirety.<\/p>\n<div id=\"storing-in-table-format\">\n<h3>Storing in Table format<\/h3>\n<p><tt>HDFStore<\/tt>\u00a0supports another\u00a0<tt>PyTables<\/tt>\u00a0format on disk, the\u00a0<tt>table<\/tt>\u00a0format. Conceptually a\u00a0<tt>table<\/tt>\u00a0is shaped very much like a DataFrame, with rows and columns. A\u00a0<tt>table<\/tt>\u00a0may be appended to in the same or other sessions. In addition, delete &amp; query type operations are supported.<\/p>\n<div>\n<div>\n<pre>In [1177]: store = HDFStore('store.h5')\n\nIn [1178]: df1 = df[0:4]\n\nIn [1179]: df2 = df[4:]\n\n# append data (creates a table automatically)\nIn [1180]: store.append('df', df1)\n\nIn [1181]: store.append('df', df2)\n\nIn [1182]: store\nOut[1182]: \n&lt;class 'pandas.io.pytables.HDFStore'&gt;\nFile path: store.h5\n\/df            frame_table  (typ-&gt;appendable,nrows-&gt;8,ncols-&gt;3,indexers-&gt;[index])\n\n# select the entire object\nIn [1183]: store.select('df')\nOut[1183]: \n                   A         B         C\n2000-01-01 -0.362543 -0.006154 -0.923061\n2000-01-02  0.895717  0.805244 -1.206412\n2000-01-03  2.565646  1.431256  1.340309\n2000-01-04 -1.170299 -0.226169  0.410835\n2000-01-05  0.813850  0.132003 -0.827317\n2000-01-06 -0.076467 -1.187678  1.130127\n2000-01-07 -1.436737 -1.413681  1.607920\n2000-01-08  1.024180  0.569605  0.875906\n\n# the type of stored data\nIn [1184]: store.root.df._v_attrs.pandas_type\nOut[1184]: 'frame_table'<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<div id=\"hierarchical-keys\">\n<h3>Hierarchical Keys<\/h3>\n<p>Keys to a store can be specified as a string. These can be in a hierarchical path-name like format (e.g.\u00a0<tt>foo\/bar\/bah<\/tt>), which will generate a hierarchy of sub-stores (or\u00a0<tt>Groups<\/tt>\u00a0in PyTables parlance). Keys can be specified with out the leading \u2018\/\u2019 and are ALWAYS absolute (e.g. \u2018foo\u2019 refers to \u2018\/foo\u2019). Removal operations can remove everying in the sub-store and BELOW, so be\u00a0<em>careful<\/em>.<\/p>\n<div>\n<div>\n<pre>In [1185]: store.put('foo\/bar\/bah', df)\n\nIn [1186]: store.append('food\/orange', df)\n\nIn [1187]: store.append('food\/apple',  df)\n\nIn [1188]: store\nOut[1188]: \n&lt;class 'pandas.io.pytables.HDFStore'&gt;\nFile path: store.h5\n\/df                     frame_table  (typ-&gt;appendable,nrows-&gt;8,ncols-&gt;3,indexers-&gt;[index])\n\/food\/apple             frame_table  (typ-&gt;appendable,nrows-&gt;8,ncols-&gt;3,indexers-&gt;[index])\n\/food\/orange            frame_table  (typ-&gt;appendable,nrows-&gt;8,ncols-&gt;3,indexers-&gt;[index])\n\/foo\/bar\/bah            frame        (shape-&gt;[8,3])                                       \n\n# a list of keys are returned\nIn [1189]: store.keys()\nOut[1189]: ['\/df', '\/food\/apple', '\/food\/orange', '\/foo\/bar\/bah']\n\n# remove all nodes under this level\nIn [1190]: store.remove('food')\n\nIn [1191]: store\nOut[1191]: \n&lt;class 'pandas.io.pytables.HDFStore'&gt;\nFile path: store.h5\n\/df                     frame_table  (typ-&gt;appendable,nrows-&gt;8,ncols-&gt;3,indexers-&gt;[index])\n\/foo\/bar\/bah            frame        (shape-&gt;[8,3])<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<div id=\"storing-mixed-types-in-a-table\">\n<h3>Storing Mixed Types in a Table<\/h3>\n<p>Storing mixed-dtype data is supported. Strings are stored as a fixed-width using the maximum size of the appended column. Subsequent appends will truncate strings at this length.<\/p>\n<p>Passing\u00a0<tt>min_itemsize={`values`:\u00a0size}<\/tt>\u00a0as a parameter to append will set a larger minimum for the string columns. Storing\u00a0<tt>floats,\u00a0strings,\u00a0ints,\u00a0bools,\u00a0datetime64<\/tt>\u00a0are currently supported. For string columns, passing\u00a0<tt>nan_rep\u00a0=\u00a0'nan'<\/tt>\u00a0to append will change the default nan representation on disk (which converts to\/from\u00a0<cite>np.nan<\/cite>), this defaults to\u00a0<cite>nan<\/cite>.<\/p>\n<div>\n<div>\n<pre>In [1192]: df_mixed = DataFrame({ 'A' : randn(8),\n   ......:                        'B' : randn(8),\n   ......:                        'C' : np.array(randn(8),dtype='float32'),\n   ......:                        'string' :'string',\n   ......:                        'int' : 1,\n   ......:                        'bool' : True,\n   ......:                        'datetime64' : Timestamp('20010102')},\n   ......:                      index=range(8))\n   ......:\n\nIn [1193]: df_mixed.ix[3:5,['A', 'B', 'string', 'datetime64']] = np.nan\n\nIn [1194]: store.append('df_mixed', df_mixed, min_itemsize = {'values': 50})\n\nIn [1195]: df_mixed1 = store.select('df_mixed')\n\nIn [1196]: df_mixed1\nOut[1196]: \n          A         B         C  bool          datetime64  int  string\n0  0.896171 -0.493662 -0.251905  True 2001-01-02 00:00:00    1  string\n1 -0.487602  0.600178 -2.213588  True 2001-01-02 00:00:00    1  string\n2 -0.082240  0.274230  1.063327  True 2001-01-02 00:00:00    1  string\n3       NaN       NaN  1.266143  True                 NaT    1     NaN\n4       NaN       NaN  0.299368  True                 NaT    1     NaN\n5       NaN       NaN -0.863838  True                 NaT    1     NaN\n6  0.432390  1.450520  0.408204  True 2001-01-02 00:00:00    1  string\n7  1.519970  0.206053 -1.048089  True 2001-01-02 00:00:00    1  string\n\nIn [1197]: df_mixed1.get_dtype_counts()\nOut[1197]: \nbool              1\ndatetime64[ns]    1\nfloat32           1\nfloat64           2\nint64             1\nobject            1\ndtype: int64\n\n# we have provided a minimum string column size\nIn [1198]: store.root.df_mixed.table\nOut[1198]: \n\/df_mixed\/table (Table(8,)) ''\n  description := {\n  \"index\": Int64Col(shape=(), dflt=0, pos=0),\n  \"values_block_0\": Float64Col(shape=(2,), dflt=0.0, pos=1),\n  \"values_block_1\": Float32Col(shape=(1,), dflt=0.0, pos=2),\n  \"values_block_2\": Int64Col(shape=(1,), dflt=0, pos=3),\n  \"values_block_3\": Int64Col(shape=(1,), dflt=0, pos=4),\n  \"values_block_4\": BoolCol(shape=(1,), dflt=False, pos=5),\n  \"values_block_5\": StringCol(itemsize=50, shape=(1,), dflt='', pos=6)}\n  byteorder := 'little'\n  chunkshape := (689,)\n  autoIndex := True\n  colindexes := {\n    \"index\": Index(6, medium, shuffle, zlib(1)).is_CSI=False}<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<div id=\"storing-multi-index-dataframes\">\n<h3>Storing Multi-Index DataFrames<\/h3>\n<p>Storing multi-index dataframes as tables is very similar to storing\/selecting from homogeneous index DataFrames.<\/p>\n<div>\n<div>\n<pre>In [1199]: index = MultiIndex(levels=[['foo', 'bar', 'baz', 'qux'],\n   ......:                            ['one', 'two', 'three']],\n   ......:                    labels=[[0, 0, 0, 1, 1, 2, 2, 3, 3, 3],\n   ......:                            [0, 1, 2, 0, 1, 1, 2, 0, 1, 2]],\n   ......:                    names=['foo', 'bar'])\n   ......:\n\nIn [1200]: df_mi = DataFrame(np.random.randn(10, 3), index=index,\n   ......:                   columns=['A', 'B', 'C'])\n   ......:\n\nIn [1201]: df_mi\nOut[1201]: \n                  A         B         C\nfoo bar                                \nfoo one   -0.025747 -0.988387  0.094055\n    two    1.262731  1.289997  0.082423\n    three -0.055758  0.536580 -0.489682\nbar one    0.369374 -0.034571 -2.484478\n    two   -0.281461  0.030711  0.109121\nbaz two    1.126203 -0.977349  1.474071\n    three -0.064034 -1.282782  0.781836\nqux one   -1.071357  0.441153  2.353925\n    two    0.583787  0.221471 -0.744471\n    three  0.758527  1.729689 -0.964980\n\nIn [1202]: store.append('df_mi',df_mi)\n\nIn [1203]: store.select('df_mi')\nOut[1203]: \n                  A         B         C\nfoo bar                                \nfoo one   -0.025747 -0.988387  0.094055\n    two    1.262731  1.289997  0.082423\n    three -0.055758  0.536580 -0.489682\nbar one    0.369374 -0.034571 -2.484478\n    two   -0.281461  0.030711  0.109121\nbaz two    1.126203 -0.977349  1.474071\n    three -0.064034 -1.282782  0.781836\nqux one   -1.071357  0.441153  2.353925\n    two    0.583787  0.221471 -0.744471\n    three  0.758527  1.729689 -0.964980\n\n# the levels are automatically included as data columns\nIn [1204]: store.select('df_mi', Term('foo=bar'))\nOut[1204]: \n                A         B         C\nfoo bar                              \nbar one  0.369374 -0.034571 -2.484478\n    two -0.281461  0.030711  0.109121<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<div id=\"querying-a-table\">\n<h3>Querying a Table<\/h3>\n<p><tt>select<\/tt>\u00a0and\u00a0<tt>delete<\/tt>\u00a0operations have an optional criterion that can be specified to select\/delete only a subset of the data. This allows one to have a very large on-disk table and retrieve only a portion of the data.<\/p>\n<p>A query is specified using the\u00a0<tt>Term<\/tt>\u00a0class under the hood.<\/p>\n<blockquote>\n<ul>\n<li>\u2018index\u2019 and \u2018columns\u2019 are supported indexers of a DataFrame<\/li>\n<li>\u2018major_axis\u2019, \u2018minor_axis\u2019, and \u2018items\u2019 are supported indexers of the Panel<\/li>\n<\/ul>\n<\/blockquote>\n<p>Valid terms can be created from\u00a0<tt>dict,\u00a0list,\u00a0tuple,\u00a0or\u00a0string<\/tt>. Objects can be embeded as values. Allowed operations are:\u00a0<tt>&lt;,\u00a0&lt;=,\u00a0&gt;,\u00a0&gt;=,\u00a0=,\u00a0!=<\/tt>.\u00a0<tt>=<\/tt>\u00a0will be inferred as an implicit set operation (e.g. if 2 or more values are provided). The following are all valid terms.<\/p>\n<blockquote>\n<ul>\n<li><tt>dict(field\u00a0=\u00a0'index',\u00a0op\u00a0=\u00a0'&gt;',\u00a0value\u00a0=\u00a0'20121114')<\/tt><\/li>\n<li><tt>('index',\u00a0'&gt;',\u00a0'20121114')<\/tt><\/li>\n<li><tt>'index\u00a0&gt;\u00a020121114'<\/tt><\/li>\n<li><tt>('index',\u00a0'&gt;',\u00a0datetime(2012,\u00a011,\u00a014))<\/tt><\/li>\n<li><tt>('index',\u00a0['20121114',\u00a0'20121115'])<\/tt><\/li>\n<li><tt>('major_axis',\u00a0'=',\u00a0Timestamp('2012\/11\/14'))<\/tt><\/li>\n<li><tt>('minor_axis',\u00a0['A',\u00a0'B'])<\/tt><\/li>\n<\/ul>\n<\/blockquote>\n<p>Queries are built up using a list of\u00a0<tt>Terms<\/tt>\u00a0(currently only\u00a0<strong>anding<\/strong>\u00a0of terms is supported). An example query for a panel might be specified as follows.\u00a0<tt>['major_axis&gt;20000102',('minor_axis',\u00a0'=',\u00a0['A',\u00a0'B'])\u00a0]<\/tt>. This is roughly translated to:\u00a0<cite>major_axis must be greater than the date 20000102 and the minor_axis must be A or B<\/cite><\/p>\n<div>\n<div>\n<pre>In [1205]: store.append('wp',wp)\n\nIn [1206]: store\nOut[1206]: \n&lt;class 'pandas.io.pytables.HDFStore'&gt;\nFile path: store.h5\n\/df                     frame_table  (typ-&gt;appendable,nrows-&gt;8,ncols-&gt;3,indexers-&gt;[index])                     \n\/df_mi                  frame_table  (typ-&gt;appendable_multi,nrows-&gt;10,ncols-&gt;5,indexers-&gt;[index],dc-&gt;[bar,foo])\n\/df_mixed               frame_table  (typ-&gt;appendable,nrows-&gt;8,ncols-&gt;7,indexers-&gt;[index])                     \n\/wp                     wide_table   (typ-&gt;appendable,nrows-&gt;20,ncols-&gt;2,indexers-&gt;[major_axis,minor_axis])    \n\/foo\/bar\/bah            frame        (shape-&gt;[8,3])                                                            \n\nIn [1207]: store.select('wp', [ Term('major_axis&gt;20000102'), Term('minor_axis', '=', ['A', 'B']) ])\nOut[1207]: \n&lt;class 'pandas.core.panel.Panel'&gt;\nDimensions: 2 (items) x 3 (major_axis) x 2 (minor_axis)\nItems axis: Item1 to Item2\nMajor_axis axis: 2000-01-03 00:00:00 to 2000-01-05 00:00:00\nMinor_axis axis: A to B<\/pre>\n<\/div>\n<\/div>\n<p>The\u00a0<tt>columns<\/tt>\u00a0keyword can be supplied to select to filter a list of the return columns, this is equivalent to passing a\u00a0<tt>Term('columns',\u00a0list_of_columns_to_filter)<\/tt><\/p>\n<div>\n<div>\n<pre>In [1208]: store.select('df', columns=['A', 'B'])\nOut[1208]: \n                   A         B\n2000-01-01 -0.362543 -0.006154\n2000-01-02  0.895717  0.805244\n2000-01-03  2.565646  1.431256\n2000-01-04 -1.170299 -0.226169\n2000-01-05  0.813850  0.132003\n2000-01-06 -0.076467 -1.187678\n2000-01-07 -1.436737 -1.413681\n2000-01-08  1.024180  0.569605<\/pre>\n<\/div>\n<\/div>\n<p><tt>start<\/tt>\u00a0and\u00a0<tt>stop<\/tt>\u00a0parameters can be specified to limit the total search space. These are in terms of the total number of rows in a table.<\/p>\n<div>\n<div>\n<pre># this is effectively what the storage of a Panel looks like\nIn [1209]: wp.to_frame()\nOut[1209]: \n                     Item1     Item2\nmajor      minor                    \n2000-01-01 A     -2.211372  0.687738\n           B      0.974466  0.176444\n           C     -2.006747  0.403310\n           D     -0.410001 -0.154951\n2000-01-02 A     -0.078638  0.301624\n           B      0.545952 -2.179861\n           C     -1.219217 -1.369849\n           D     -1.226825 -0.954208\n2000-01-03 A      0.769804  1.462696\n           B     -1.281247 -1.743161\n           C     -0.727707 -0.826591\n           D     -0.121306 -0.345352\n2000-01-04 A     -0.097883  1.314232\n           B      0.695775  0.690579\n           C      0.341734  0.995761\n           D      0.959726  2.396780\n2000-01-05 A     -1.110336  0.014871\n           B     -0.619976  3.357427\n           C      0.149748 -0.317441\n           D     -0.732339 -1.236269\n\n# limiting the search\nIn [1210]: store.select('wp',[ Term('major_axis&gt;20000102'),\n   ......:                     Term('minor_axis', '=', ['A','B']) ],\n   ......:              start=0, stop=10)\n   ......:\nOut[1210]: \n&lt;class 'pandas.core.panel.Panel'&gt;\nDimensions: 2 (items) x 1 (major_axis) x 2 (minor_axis)\nItems axis: Item1 to Item2\nMajor_axis axis: 2000-01-03 00:00:00 to 2000-01-03 00:00:00\nMinor_axis axis: A to B<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<div id=\"indexing\">\n<h3>Indexing<\/h3>\n<p>You can create\/modify an index for a table with\u00a0<tt>create_table_index<\/tt>\u00a0after data is already in the table (after and\u00a0<tt>append\/put<\/tt>\u00a0operation). Creating a table index is\u00a0<strong>highly<\/strong>\u00a0encouraged. This will speed your queries a great deal when you use a\u00a0<tt>select<\/tt>\u00a0with the indexed dimension as the\u00a0<tt>where<\/tt>.\u00a0<strong>Indexes are automagically created (starting 0.10.1)<\/strong>\u00a0on the indexables and any data columns you specify. This behavior can be turned off by passing\u00a0<tt>index=False<\/tt>\u00a0to\u00a0<tt>append<\/tt>.<\/p>\n<div>\n<div>\n<pre># we have automagically already created an index (in the first section)\nIn [1211]: i = store.root.df.table.cols.index.index\n\nIn [1212]: i.optlevel, i.kind\nOut[1212]: (6, 'medium')\n\n# change an index by passing new parameters\nIn [1213]: store.create_table_index('df', optlevel=9, kind='full')\n\nIn [1214]: i = store.root.df.table.cols.index.index\n\nIn [1215]: i.optlevel, i.kind\nOut[1215]: (9, 'full')<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<div id=\"query-via-data-columns\">\n<h3>Query via Data Columns<\/h3>\n<p>You can designate (and index) certain columns that you want to be able to perform queries (other than the\u00a0<cite>indexable<\/cite>\u00a0columns, which you can always query). For instance say you want to perform this common operation, on-disk, and return just the frame that matches this query. You can specify\u00a0<tt>data_columns\u00a0=\u00a0True<\/tt>\u00a0to force all columns to be data_columns<\/p>\n<div>\n<div>\n<pre>In [1216]: df_dc = df.copy()\n\nIn [1217]: df_dc['string'] = 'foo'\n\nIn [1218]: df_dc.ix[4:6,'string'] = np.nan\n\nIn [1219]: df_dc.ix[7:9,'string'] = 'bar'\n\nIn [1220]: df_dc['string2'] = 'cool'\n\nIn [1221]: df_dc\nOut[1221]: \n                   A         B         C string string2\n2000-01-01 -0.362543 -0.006154 -0.923061    foo    cool\n2000-01-02  0.895717  0.805244 -1.206412    foo    cool\n2000-01-03  2.565646  1.431256  1.340309    foo    cool\n2000-01-04 -1.170299 -0.226169  0.410835    foo    cool\n2000-01-05  0.813850  0.132003 -0.827317    NaN    cool\n2000-01-06 -0.076467 -1.187678  1.130127    NaN    cool\n2000-01-07 -1.436737 -1.413681  1.607920    foo    cool\n2000-01-08  1.024180  0.569605  0.875906    bar    cool\n\n# on-disk operations\nIn [1222]: store.append('df_dc', df_dc, data_columns = ['B', 'C', 'string', 'string2'])\n\nIn [1223]: store.select('df_dc', [ Term('B&gt;0') ])\nOut[1223]: \n                   A         B         C string string2\n2000-01-02  0.895717  0.805244 -1.206412    foo    cool\n2000-01-03  2.565646  1.431256  1.340309    foo    cool\n2000-01-05  0.813850  0.132003 -0.827317    NaN    cool\n2000-01-08  1.024180  0.569605  0.875906    bar    cool\n\n# getting creative\nIn [1224]: store.select('df_dc', ['B &gt; 0', 'C &gt; 0', 'string == foo'])\nOut[1224]: \n                   A         B         C string string2\n2000-01-03  2.565646  1.431256  1.340309    foo    cool\n\n# this is in-memory version of this type of selection\nIn [1225]: df_dc[(df_dc.B &gt; 0) &amp; (df_dc.C &gt; 0) &amp; (df_dc.string == 'foo')]\nOut[1225]: \n                   A         B         C string string2\n2000-01-03  2.565646  1.431256  1.340309    foo    cool\n\n# we have automagically created this index and that the B\/C\/string\/string2\n# columns are stored separately as ``PyTables`` columns\nIn [1226]: store.root.df_dc.table\nOut[1226]: \n\/df_dc\/table (Table(8,)) ''\n  description := {\n  \"index\": Int64Col(shape=(), dflt=0, pos=0),\n  \"values_block_0\": Float64Col(shape=(1,), dflt=0.0, pos=1),\n  \"B\": Float64Col(shape=(), dflt=0.0, pos=2),\n  \"C\": Float64Col(shape=(), dflt=0.0, pos=3),\n  \"string\": StringCol(itemsize=3, shape=(), dflt='', pos=4),\n  \"string2\": StringCol(itemsize=4, shape=(), dflt='', pos=5)}\n  byteorder := 'little'\n  chunkshape := (1680,)\n  autoIndex := True\n  colindexes := {\n    \"index\": Index(6, medium, shuffle, zlib(1)).is_CSI=False,\n    \"C\": Index(6, medium, shuffle, zlib(1)).is_CSI=False,\n    \"B\": Index(6, medium, shuffle, zlib(1)).is_CSI=False,\n    \"string2\": Index(6, medium, shuffle, zlib(1)).is_CSI=False,\n    \"string\": Index(6, medium, shuffle, zlib(1)).is_CSI=False}<\/pre>\n<\/div>\n<\/div>\n<p>There is some performance degredation by making lots of columns into\u00a0<cite>data columns<\/cite>, so it is up to the user to designate these. In addition, you cannot change data columns (nor indexables) after the first append\/put operation (Of course you can simply read in the data and create a new table!)<\/p>\n<\/div>\n<div id=\"iterator\">\n<h3>Iterator<\/h3>\n<p>Starting in 0.11, you can pass,\u00a0<tt>iterator=True<\/tt>\u00a0or\u00a0<tt>chunksize=number_in_a_chunk<\/tt>\u00a0to\u00a0<tt>select<\/tt>\u00a0and<tt>select_as_multiple<\/tt>\u00a0to return an iterator on the results. The default is 50,000 rows returned in a chunk.<\/p>\n<div>\n<div>\n<pre>In [1227]: for df in store.select('df', chunksize=3):\n   ......:    print df\n   ......:\n                   A         B         C\n2000-01-01 -0.362543 -0.006154 -0.923061\n2000-01-02  0.895717  0.805244 -1.206412\n2000-01-03  2.565646  1.431256  1.340309\n                   A         B         C\n2000-01-04 -1.170299 -0.226169  0.410835\n2000-01-05  0.813850  0.132003 -0.827317\n2000-01-06 -0.076467 -1.187678  1.130127\n                   A         B         C\n2000-01-07 -1.436737 -1.413681  1.607920\n2000-01-08  1.024180  0.569605  0.875906<\/pre>\n<\/div>\n<\/div>\n<p>Note, that the chunksize keyword applies to the\u00a0<strong>returned<\/strong>\u00a0rows. So if you are doing a query, then that set will be subdivided and returned in the iterator. Keep in mind that if you do not pass a\u00a0<tt>where<\/tt>\u00a0selection criteria then the\u00a0<tt>nrows<\/tt>\u00a0of the table are considered.<\/p>\n<\/div>\n<div id=\"advanced-queries\">\n<h3>Advanced Queries<\/h3>\n<p><strong>Unique<\/strong><\/p>\n<p>To retrieve the\u00a0<em>unique<\/em>\u00a0values of an indexable or data column, use the method\u00a0<tt>unique<\/tt>. This will, for example, enable you to get the index very quickly. Note\u00a0<tt>nan<\/tt>\u00a0are excluded from the result set.<\/p>\n<div>\n<div>\n<pre>In [1228]: store.unique('df_dc', 'index')\nOut[1228]: \n&lt;class 'pandas.tseries.index.DatetimeIndex'&gt;\n[2000-01-01 00:00:00, ..., 2000-01-08 00:00:00]\nLength: 8, Freq: None, Timezone: None\n\nIn [1229]: store.unique('df_dc', 'string')\nOut[1229]: Index([bar, foo], dtype=object)<\/pre>\n<\/div>\n<\/div>\n<p><strong>Replicating or<\/strong><\/p>\n<p><tt>not<\/tt>\u00a0and\u00a0<tt>or<\/tt>\u00a0conditions are unsupported at this time; however,\u00a0<tt>or<\/tt>\u00a0operations are easy to replicate, by repeatedly applying the criteria to the table, and then\u00a0<tt>concat<\/tt>\u00a0the results.<\/p>\n<div>\n<div>\n<pre>In [1230]: crit1 = [ Term('B&gt;0'), Term('C&gt;0'), Term('string=foo') ]\n\nIn [1231]: crit2 = [ Term('B&lt;0'), Term('C&gt;0'), Term('string=foo') ]\n\nIn [1232]: concat([store.select('df_dc',c) for c in [crit1, crit2]])\nOut[1232]: \n                   A         B         C string string2\n2000-01-03  2.565646  1.431256  1.340309    foo    cool\n2000-01-04 -1.170299 -0.226169  0.410835    foo    cool\n2000-01-07 -1.436737 -1.413681  1.607920    foo    cool<\/pre>\n<\/div>\n<\/div>\n<p><strong>Storer Object<\/strong><\/p>\n<p>If you want to inspect the stored object, retrieve via\u00a0<tt>get_storer<\/tt>. You could use this programmatically to say get the number of rows in an object.<\/p>\n<div>\n<div>\n<pre>In [1233]: store.get_storer('df_dc').nrows\nOut[1233]: 8<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<div id=\"multiple-table-queries\">\n<h3>Multiple Table Queries<\/h3>\n<p>New in 0.10.1 are the methods\u00a0<tt>append_to_multple<\/tt>\u00a0and\u00a0<tt>select_as_multiple<\/tt>, that can perform appending\/selecting from multiple tables at once. The idea is to have one table (call it the selector table) that you index most\/all of the columns, and perform your queries. The other table(s) are data tables that are indexed the same as the selector table. You can then perform a very fast query on the selector table, yet get lots of data back. This method works similar to having a very wide table, but is more efficient in terms of queries.<\/p>\n<p>Note,\u00a0<strong>THE USER IS RESPONSIBLE FOR SYNCHRONIZING THE TABLES<\/strong>. This means, append to the tables in the same order;\u00a0<tt>append_to_multiple<\/tt>\u00a0splits a single object to multiple tables, given a specification (as a dictionary). This dictionary is a mapping of the table names to the \u2018columns\u2019 you want included in that table. Pass a\u00a0<cite>None<\/cite>\u00a0for a single table (optional) to let it have the remaining columns. The argument\u00a0<tt>selector<\/tt>\u00a0defines which table is the selector table.<\/p>\n<div>\n<div>\n<pre>In [1234]: df_mt = DataFrame(randn(8, 6), index=date_range('1\/1\/2000', periods=8),\n   ......:                                columns=['A', 'B', 'C', 'D', 'E', 'F'])\n   ......:\n\nIn [1235]: df_mt['foo'] = 'bar'\n\n# you can also create the tables individually\nIn [1236]: store.append_to_multiple({'df1_mt': ['A', 'B'], 'df2_mt': None },\n   ......:                           df_mt, selector='df1_mt')\n   ......:\n\nIn [1237]: store\nOut[1237]: \n&lt;class 'pandas.io.pytables.HDFStore'&gt;\nFile path: store.h5\n\/df                     frame_table  (typ-&gt;appendable,nrows-&gt;8,ncols-&gt;3,indexers-&gt;[index])                         \n\/df1_mt                 frame_table  (typ-&gt;appendable,nrows-&gt;8,ncols-&gt;2,indexers-&gt;[index],dc-&gt;[A,B])               \n\/df2_mt                 frame_table  (typ-&gt;appendable,nrows-&gt;8,ncols-&gt;5,indexers-&gt;[index])                         \n\/df_dc                  frame_table  (typ-&gt;appendable,nrows-&gt;8,ncols-&gt;5,indexers-&gt;[index],dc-&gt;[B,C,string,string2])\n\/df_mi                  frame_table  (typ-&gt;appendable_multi,nrows-&gt;10,ncols-&gt;5,indexers-&gt;[index],dc-&gt;[bar,foo])    \n\/df_mixed               frame_table  (typ-&gt;appendable,nrows-&gt;8,ncols-&gt;7,indexers-&gt;[index])                         \n\/wp                     wide_table   (typ-&gt;appendable,nrows-&gt;20,ncols-&gt;2,indexers-&gt;[major_axis,minor_axis])        \n\/foo\/bar\/bah            frame        (shape-&gt;[8,3])                                                                \n\n# indiviual tables were created\nIn [1238]: store.select('df1_mt')\nOut[1238]: \n                   A         B\n2000-01-01 -0.845696 -1.340896\n2000-01-02  0.888782  0.228440\n2000-01-03 -1.066969 -0.303421\n2000-01-04  1.574159  1.588931\n2000-01-05 -0.284319  0.650776\n2000-01-06  1.613616  0.464000\n2000-01-07 -1.134623 -1.561819\n2000-01-08  0.068159 -0.057873\n\nIn [1239]: store.select('df2_mt')\nOut[1239]: \n                   C         D         E         F  foo\n2000-01-01  1.846883 -1.328865  1.682706 -1.717693  bar\n2000-01-02  0.901805  1.171216  0.520260 -1.197071  bar\n2000-01-03 -0.858447  0.306996 -0.028665  0.384316  bar\n2000-01-04  0.476720  0.473424 -0.242861 -0.014805  bar\n2000-01-05 -1.461665 -1.137707 -0.891060 -0.693921  bar\n2000-01-06  0.227371 -0.496922  0.306389 -2.290613  bar\n2000-01-07 -0.260838  0.281957  1.523962 -0.902937  bar\n2000-01-08 -0.368204 -1.144073  0.861209  0.800193  bar\n\n# as a multiple\nIn [1240]: store.select_as_multiple(['df1_mt', 'df2_mt'], where=['A&gt;0', 'B&gt;0'],\n   ......:                           selector = 'df1_mt')\n   ......:\nOut[1240]: \n                   A         B         C         D         E         F  foo\n2000-01-02  0.888782  0.228440  0.901805  1.171216  0.520260 -1.197071  bar\n2000-01-04  1.574159  1.588931  0.476720  0.473424 -0.242861 -0.014805  bar\n2000-01-06  1.613616  0.464000  0.227371 -0.496922  0.306389 -2.290613  bar<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<div id=\"delete-from-a-table\">\n<h3>Delete from a Table<\/h3>\n<p>You can delete from a table selectively by specifying a\u00a0<tt>where<\/tt>. In deleting rows, it is important to understand the\u00a0<tt>PyTables<\/tt>\u00a0deletes rows by erasing the rows, then\u00a0<strong>moving<\/strong>\u00a0the following data. Thus deleting can potentially be a very expensive operation depending on the orientation of your data. This is especially true in higher dimensional objects (<tt>Panel<\/tt>\u00a0and<tt>Panel4D<\/tt>). To get optimal deletion speed, it pays to have the dimension you are deleting be the first of the\u00a0<tt>indexables<\/tt>.<\/p>\n<p>Data is ordered (on the disk) in terms of the\u00a0<tt>indexables<\/tt>. Here\u2019s a simple use case. You store panel-type data, with dates in the\u00a0<tt>major_axis<\/tt>\u00a0and ids in the\u00a0<tt>minor_axis<\/tt>. The data is then interleaved like this:<\/p>\n<blockquote>\n<ul>\n<li>\n<dl>\n<dt>date_1<\/dt>\n<dd>\n<ul>\n<li>id_1<\/li>\n<li>id_2<\/li>\n<li>.<\/li>\n<li>id_n<\/li>\n<\/ul>\n<\/dd>\n<\/dl>\n<\/li>\n<li>\n<dl>\n<dt>date_2<\/dt>\n<dd>\n<ul>\n<li>id_1<\/li>\n<li>.<\/li>\n<li>id_n<\/li>\n<\/ul>\n<\/dd>\n<\/dl>\n<\/li>\n<\/ul>\n<\/blockquote>\n<p>It should be clear that a delete operation on the\u00a0<tt>major_axis<\/tt>\u00a0will be fairly quick, as one chunk is removed, then the following data moved. On the other hand a delete operation on the<tt>minor_axis<\/tt>\u00a0will be very expensive. In this case it would almost certainly be faster to rewrite the table using a\u00a0<tt>where<\/tt>\u00a0that selects all but the missing data.<\/p>\n<div>\n<div>\n<pre># returns the number of rows deleted\nIn [1241]: store.remove('wp', 'major_axis&gt;20000102' )\nOut[1241]: 12\n\nIn [1242]: store.select('wp')\nOut[1242]: \n&lt;class 'pandas.core.panel.Panel'&gt;\nDimensions: 2 (items) x 2 (major_axis) x 4 (minor_axis)\nItems axis: Item1 to Item2\nMajor_axis axis: 2000-01-01 00:00:00 to 2000-01-02 00:00:00\nMinor_axis axis: A to D<\/pre>\n<\/div>\n<\/div>\n<p>Please note that HDF5\u00a0<strong>DOES NOT RECLAIM SPACE<\/strong>\u00a0in the h5 files automatically. Thus, repeatedly deleting (or removing nodes) and adding again\u00a0<strong>WILL TEND TO INCREASE THE FILE SIZE<\/strong>. To\u00a0<em>clean<\/em>\u00a0the file, use\u00a0<tt>ptrepack<\/tt>\u00a0(see below).<\/p>\n<\/div>\n<div id=\"compression\">\n<h3>Compression<\/h3>\n<p><tt>PyTables<\/tt>\u00a0allows the stored data to be compressed. Tthis applies to all kinds of stores, not just tables.<\/p>\n<blockquote>\n<ul>\n<li>Pass\u00a0<tt>complevel=int<\/tt>\u00a0for a compression level (1-9, with 0 being no compression, and the default)<\/li>\n<li>Pass\u00a0<tt>complib=lib<\/tt>\u00a0where lib is any of\u00a0<tt>zlib,\u00a0bzip2,\u00a0lzo,\u00a0blosc<\/tt>\u00a0for whichever compression library you prefer.<\/li>\n<\/ul>\n<\/blockquote>\n<p><tt>HDFStore<\/tt>\u00a0will use the file based compression scheme if no overriding\u00a0<tt>complib<\/tt>\u00a0or\u00a0<tt>complevel<\/tt>options are provided.\u00a0<tt>blosc<\/tt>\u00a0offers very fast compression, and is my most used. Note that<tt>lzo<\/tt>\u00a0and\u00a0<tt>bzip2<\/tt>\u00a0may not be installed (by Python) by default.<\/p>\n<p>Compression for all objects within the file<\/p>\n<blockquote>\n<ul>\n<li><tt>store_compressed\u00a0=\u00a0HDFStore('store_compressed.h5',\u00a0complevel=9,\u00a0complib='blosc')<\/tt><\/li>\n<\/ul>\n<\/blockquote>\n<p>Or on-the-fly compression (this only applies to tables). You can turn off file compression for a specific table by passing\u00a0<tt>complevel=0<\/tt><\/p>\n<blockquote>\n<ul>\n<li><tt>store.append('df',\u00a0df,\u00a0complib='zlib',\u00a0complevel=5)<\/tt><\/li>\n<\/ul>\n<\/blockquote>\n<p><strong>ptrepack<\/strong><\/p>\n<p><tt>PyTables<\/tt>\u00a0offer better write performance when compressed after writing them, as opposed to turning on compression at the very beginning. You can use the supplied\u00a0<tt>PyTables<\/tt>\u00a0utility<tt>ptrepack<\/tt>. In addition,\u00a0<tt>ptrepack<\/tt>\u00a0can change compression levels after the fact.<\/p>\n<blockquote>\n<ul>\n<li><tt>ptrepack\u00a0--chunkshape=auto\u00a0--propindexes\u00a0--complevel=9\u00a0--complib=blosc\u00a0in.h5\u00a0out.h5<\/tt><\/li>\n<\/ul>\n<\/blockquote>\n<p>Furthermore\u00a0<tt>ptrepack\u00a0in.h5\u00a0out.h5<\/tt>\u00a0will\u00a0<em>repack<\/em>\u00a0the file to allow you to reuse previously deleted space. Aalternatively, one can simply remove the file and write again, or use the<tt>copy<\/tt>\u00a0method.<\/p>\n<\/div>\n<div id=\"notes-caveats\">\n<h3>Notes &amp; Caveats<\/h3>\n<blockquote>\n<ul>\n<li>Once a\u00a0<tt>table<\/tt>\u00a0is created its items (Panel) \/ columns (DataFrame) are fixed; only exactly the same columns can be appended<\/li>\n<li>If a row has\u00a0<tt>np.nan<\/tt>\u00a0for\u00a0<strong>EVERY COLUMN<\/strong>\u00a0(having a\u00a0<tt>nan<\/tt>\u00a0in a string, or a\u00a0<tt>NaT<\/tt>\u00a0in a datetime-like column counts as having a value), then those rows\u00a0<strong>WILL BE DROPPED IMPLICITLY<\/strong>. This limitation\u00a0<em>may<\/em>\u00a0be addressed in the future.<\/li>\n<li>You can not append\/select\/delete to a non-table (table creation is determined on the first append, or by passing\u00a0<tt>table=True<\/tt>\u00a0in a put operation)<\/li>\n<li><tt>HDFStore<\/tt>\u00a0is\u00a0<strong>not-threadsafe for writing<\/strong>. The underlying\u00a0<tt>PyTables<\/tt>\u00a0only supports concurrent reads (via threading or processes). If you need reading and writing\u00a0<em>at the same time<\/em>, you need to serialize these operations in a single thread in a single process. You will corrupt your data otherwise. See the issue &lt;<a href=\"https:\/\/github.com\/pydata\/pandas\/issues\/2397\">https:\/\/github.com\/pydata\/pandas\/issues\/2397<\/a>&gt; for more information.<\/li>\n<li><tt>PyTables<\/tt>\u00a0only supports fixed-width string columns in\u00a0<tt>tables<\/tt>. The sizes of a string based indexing column (e.g.\u00a0<em>columns<\/em>\u00a0or\u00a0<em>minor_axis<\/em>) are determined as the maximum size of the elements in that axis or by passing the parameter<tt>min_itemsize<\/tt>\u00a0on the first table creation (<tt>min_itemsize<\/tt>\u00a0can be an integer or a dict of column name to an integer). If subsequent appends introduce elements in the indexing axis that are larger than the supported indexer, an Exception will be raised (otherwise you could have a silent truncation of these indexers, leading to loss of information). Just to be clear, this fixed-width restriction applies to<strong>indexables<\/strong>\u00a0(the indexing columns) and\u00a0<strong>string values<\/strong>\u00a0in a mixed_type table.\n<div>\n<div>\n<pre>In [1243]: store.append('wp_big_strings', wp, min_itemsize = { 'minor_axis' : 30 })\n\nIn [1244]: wp = wp.rename_axis(lambda x: x + '_big_strings', axis=2)\n\nIn [1245]: store.append('wp_big_strings', wp)\n\nIn [1246]: store.select('wp_big_strings')\nOut[1246]: \n&lt;class 'pandas.core.panel.Panel'&gt;\nDimensions: 2 (items) x 5 (major_axis) x 8 (minor_axis)\nItems axis: Item1 to Item2\nMajor_axis axis: 2000-01-01 00:00:00 to 2000-01-05 00:00:00\nMinor_axis axis: A to D_big_strings\n\n# we have provided a minimum minor_axis indexable size\nIn [1247]: store.root.wp_big_strings.table\nOut[1247]: \n\/wp_big_strings\/table (Table(40,)) ''\n  description := {\n  \"major_axis\": Int64Col(shape=(), dflt=0, pos=0),\n  \"minor_axis\": StringCol(itemsize=30, shape=(), dflt='', pos=1),\n  \"values_block_0\": Float64Col(shape=(2,), dflt=0.0, pos=2)}\n  byteorder := 'little'\n  chunkshape := (1213,)\n  autoIndex := True\n  colindexes := {\n    \"major_axis\": Index(6, medium, shuffle, zlib(1)).is_CSI=False,\n    \"minor_axis\": Index(6, medium, shuffle, zlib(1)).is_CSI=False}<\/pre>\n<\/div>\n<\/div>\n<\/li>\n<\/ul>\n<\/blockquote>\n<\/div>\n<div id=\"datatypes\">\n<h3>DataTypes<\/h3>\n<p><tt>HDFStore<\/tt>\u00a0will map an object dtype to the\u00a0<tt>PyTables<\/tt>\u00a0underlying dtype. This means the following types are known to work:<\/p>\n<blockquote>\n<ul>\n<li>floating :\u00a0<tt>float64,\u00a0float32,\u00a0float16<\/tt>\u00a0<em>(using<\/em>\u00a0<tt>np.nan<\/tt>\u00a0<em>to represent invalid values)<\/em><\/li>\n<li>integer :\u00a0<tt>int64,\u00a0int32,\u00a0int8,\u00a0uint64,\u00a0uint32,\u00a0uint8<\/tt><\/li>\n<li>bool<\/li>\n<li>datetime64[ns]\u00a0<em>(using<\/em>\u00a0<tt>NaT<\/tt>\u00a0<em>to represent invalid values)<\/em><\/li>\n<li>object :\u00a0<tt>strings<\/tt>\u00a0<em>(using<\/em>\u00a0<tt>np.nan<\/tt>\u00a0<em>to represent invalid values)<\/em><\/li>\n<\/ul>\n<\/blockquote>\n<p>Currently,\u00a0<tt>unicode<\/tt>\u00a0and\u00a0<tt>datetime<\/tt>\u00a0columns (represented with a dtype of\u00a0<tt>object<\/tt>),\u00a0<strong>WILL FAIL<\/strong>. In addition, even though a column may look like a\u00a0<tt>datetime64[ns]<\/tt>, if it contains\u00a0<tt>np.nan<\/tt>, this<strong>WILL FAIL<\/strong>. You can try to convert datetimelike columns to proper\u00a0<tt>datetime64[ns]<\/tt>\u00a0columns, that possibily contain\u00a0<tt>NaT<\/tt>\u00a0to represent invalid values. (Some of these issues have been addressed and these conversion may not be necessary in future versions of pandas)<\/p>\n<blockquote>\n<div>\n<div>\n<pre>In [1248]: import datetime\n\nIn [1249]: df = DataFrame(dict(datelike=Series([datetime.datetime(2001, 1, 1),\n   ......:                                      datetime.datetime(2001, 1, 2), np.nan])))\n   ......:\n\nIn [1250]: df\nOut[1250]: \n              datelike\n0  2001-01-01 00:00:00\n1  2001-01-02 00:00:00\n2                  NaN\n\nIn [1251]: df.dtypes\nOut[1251]: \ndatelike    object\ndtype: object\n\n# to convert\nIn [1252]: df['datelike'] = Series(df['datelike'].values, dtype='M8[ns]')\n\nIn [1253]: df\nOut[1253]: \n             datelike\n0 2001-01-01 00:00:00\n1 2001-01-02 00:00:00\n2                 NaT\n\nIn [1254]: df.dtypes\nOut[1254]: \ndatelike    datetime64[ns]\ndtype: object<\/pre>\n<\/div>\n<\/div>\n<\/blockquote>\n<\/div>\n<div id=\"external-compatibility\">\n<h3>External Compatibility<\/h3>\n<p><tt>HDFStore<\/tt>\u00a0write storer objects in specific formats suitable for producing loss-less roundtrips to pandas objects. For external compatibility,\u00a0<tt>HDFStore<\/tt>\u00a0can read native\u00a0<tt>PyTables<\/tt>\u00a0format tables. It is possible to write an\u00a0<tt>HDFStore<\/tt>\u00a0object that can easily be imported into\u00a0<tt>R<\/tt>\u00a0using the\u00a0<tt>rhdf5<\/tt>library. Create a table format store like this:<\/p>\n<blockquote>\n<div>\n<div>\n<pre>In [1255]: store_export = HDFStore('export.h5')\n\nIn [1256]: store_export.append('df_dc', df_dc, data_columns=df_dc.columns)\n\nIn [1257]: store_export\nOut[1257]: \n&lt;class 'pandas.io.pytables.HDFStore'&gt;\nFile path: export.h5\n\/df_dc            frame_table  (typ-&gt;appendable,nrows-&gt;8,ncols-&gt;5,indexers-&gt;[index],dc-&gt;[A,B,C,string,string2])<\/pre>\n<\/div>\n<\/div>\n<\/blockquote>\n<\/div>\n<div id=\"backwards-compatibility\">\n<h3>Backwards Compatibility<\/h3>\n<p>0.10.1 of\u00a0<tt>HDFStore<\/tt>\u00a0is backwards compatible for reading tables created in a prior version of pandas however, query terms using the prior (undocumented) methodology are unsupported.<tt>HDFStore<\/tt>\u00a0will issue a warning if you try to use a prior-version format file. You must read in the entire file and write it out using the new format, using the method\u00a0<tt>copy<\/tt>\u00a0to take advantage of the updates. The group attribute\u00a0<tt>pandas_version<\/tt>\u00a0contains the version information.\u00a0<tt>copy<\/tt>\u00a0takes a number of options, please see the docstring.<\/p>\n<blockquote>\n<div>\n<div>\n<pre># a legacy store\nIn [1258]: legacy_store = HDFStore(legacy_file_path,'r')\n\nIn [1259]: legacy_store\nOut[1259]: \n&lt;class 'pandas.io.pytables.HDFStore'&gt;\nFile path: \/home\/chang\/tmp\/doc_pandas\/doc\/source\/_static\/legacy_0.10.h5\n\/a                    series       (shape-&gt;[30])                                                                        \n\/b                    frame        (shape-&gt;[30,4])                                                                      \n\/df1_mixed            frame_table [0.10.0] (typ-&gt;appendable,nrows-&gt;30,ncols-&gt;11,indexers-&gt;[index])                      \n\/p1_mixed             wide_table  [0.10.0] (typ-&gt;appendable,nrows-&gt;120,ncols-&gt;9,indexers-&gt;[major_axis,minor_axis])      \n\/p4d_mixed            ndim_table  [0.10.0] (typ-&gt;appendable,nrows-&gt;360,ncols-&gt;9,indexers-&gt;[items,major_axis,minor_axis])\n\/foo\/bar              wide         (shape-&gt;[3,30,4])                                                                    \n\n# copy (and return the new handle)\nIn [1260]: new_store = legacy_store.copy('store_new.h5')\n\nIn [1261]: new_store\nOut[1261]: \n&lt;class 'pandas.io.pytables.HDFStore'&gt;\nFile path: store_new.h5\n\/a                    series       (shape-&gt;[30])                                                                \n\/b                    frame        (shape-&gt;[30,4])                                                              \n\/df1_mixed            frame_table  (typ-&gt;appendable,nrows-&gt;30,ncols-&gt;11,indexers-&gt;[index])                      \n\/p1_mixed             wide_table   (typ-&gt;appendable,nrows-&gt;120,ncols-&gt;9,indexers-&gt;[major_axis,minor_axis])      \n\/p4d_mixed            wide_table   (typ-&gt;appendable,nrows-&gt;360,ncols-&gt;9,indexers-&gt;[items,major_axis,minor_axis])\n\/foo\/bar              wide         (shape-&gt;[3,30,4])                                                            \n\nIn [1262]: new_store.close()<\/pre>\n<\/div>\n<\/div>\n<\/blockquote>\n<\/div>\n<div id=\"performance\">\n<h3>Performance<\/h3>\n<blockquote>\n<ul>\n<li><tt>Tables<\/tt>\u00a0come with a writing performance penalty as compared to regular stores. The benefit is the ability to append\/delete and query (potentially very large amounts of data). Write times are generally longer as compared with regular stores. Query times can be quite fast, especially on an indexed axis.<\/li>\n<li>You can pass\u00a0<tt>chunksize=an\u00a0integer<\/tt>\u00a0to\u00a0<tt>append<\/tt>, to change the writing chunksize (default is 50000). This will signficantly lower your memory usage on writing.<\/li>\n<li>You can pass\u00a0<tt>expectedrows=an\u00a0integer<\/tt>\u00a0to the first\u00a0<tt>append<\/tt>, to set the TOTAL number of expectedrows that\u00a0<tt>PyTables<\/tt>\u00a0will expected. This will optimize read\/write performance.<\/li>\n<li>Duplicate rows can be written to tables, but are filtered out in selection (with the last items being selected; thus a table is unique on major, minor pairs)<\/li>\n<li>A\u00a0<tt>PerformanceWarning<\/tt>\u00a0will be raised if you are attempting to store types that will be pickled by PyTables (rather than stored as endemic types). See &lt;<a href=\"http:\/\/stackoverflow.com\/questions\/14355151\/how-to-make-pandas-hdfstore-put-operation-faster\/14370190#14370190\">http:\/\/stackoverflow.com\/questions\/14355151\/how-to-make-pandas-hdfstore-put-operation-faster\/14370190#14370190<\/a>&gt; for more information and some solutions.<\/li>\n<\/ul>\n<\/blockquote>\n<\/div>\n<div id=\"experimental\">\n<h3>Experimental<\/h3>\n<p>HDFStore supports\u00a0<tt>Panel4D<\/tt>\u00a0storage.<\/p>\n<div>\n<div>\n<pre>In [1263]: p4d = Panel4D({ 'l1' : wp })\n\nIn [1264]: p4d\nOut[1264]: \n&lt;class 'pandas.core.panelnd.Panel4D'&gt;\nDimensions: 1 (labels) x 2 (items) x 5 (major_axis) x 4 (minor_axis)\nLabels axis: l1 to l1\nItems axis: Item1 to Item2\nMajor_axis axis: 2000-01-01 00:00:00 to 2000-01-05 00:00:00\nMinor_axis axis: A_big_strings to D_big_strings\n\nIn [1265]: store.append('p4d', p4d)\n\nIn [1266]: store\nOut[1266]: \n&lt;class 'pandas.io.pytables.HDFStore'&gt;\nFile path: store.h5\n\/df                        frame_table  (typ-&gt;appendable,nrows-&gt;8,ncols-&gt;3,indexers-&gt;[index])                         \n\/df1_mt                    frame_table  (typ-&gt;appendable,nrows-&gt;8,ncols-&gt;2,indexers-&gt;[index],dc-&gt;[A,B])               \n\/df2_mt                    frame_table  (typ-&gt;appendable,nrows-&gt;8,ncols-&gt;5,indexers-&gt;[index])                         \n\/df_dc                     frame_table  (typ-&gt;appendable,nrows-&gt;8,ncols-&gt;5,indexers-&gt;[index],dc-&gt;[B,C,string,string2])\n\/df_mi                     frame_table  (typ-&gt;appendable_multi,nrows-&gt;10,ncols-&gt;5,indexers-&gt;[index],dc-&gt;[bar,foo])    \n\/df_mixed                  frame_table  (typ-&gt;appendable,nrows-&gt;8,ncols-&gt;7,indexers-&gt;[index])                         \n\/p4d                       wide_table   (typ-&gt;appendable,nrows-&gt;40,ncols-&gt;1,indexers-&gt;[items,major_axis,minor_axis])  \n\/wp                        wide_table   (typ-&gt;appendable,nrows-&gt;8,ncols-&gt;2,indexers-&gt;[major_axis,minor_axis])         \n\/wp_big_strings            wide_table   (typ-&gt;appendable,nrows-&gt;40,ncols-&gt;2,indexers-&gt;[major_axis,minor_axis])        \n\/foo\/bar\/bah               frame        (shape-&gt;[8,3])<\/pre>\n<\/div>\n<\/div>\n<p>These, by default, index the three axes\u00a0<tt>items,\u00a0major_axis,\u00a0minor_axis<\/tt>. On an\u00a0<tt>AppendableTable<\/tt>it is possible to setup with the first append a different indexing scheme, depending on how you want to store your data. Pass the\u00a0<tt>axes<\/tt>\u00a0keyword with a list of dimension (currently must by exactly 1 less than the total dimensions of the object). This cannot be changed after table creation.<\/p>\n<div>\n<div>\n<pre>In [1267]: store.append('p4d2', p4d, axes=['labels', 'major_axis', 'minor_axis'])\n\nIn [1268]: store\nOut[1268]: \n&lt;class 'pandas.io.pytables.HDFStore'&gt;\nFile path: store.h5\n\/df                        frame_table  (typ-&gt;appendable,nrows-&gt;8,ncols-&gt;3,indexers-&gt;[index])                         \n\/df1_mt                    frame_table  (typ-&gt;appendable,nrows-&gt;8,ncols-&gt;2,indexers-&gt;[index],dc-&gt;[A,B])               \n\/df2_mt                    frame_table  (typ-&gt;appendable,nrows-&gt;8,ncols-&gt;5,indexers-&gt;[index])                         \n\/df_dc                     frame_table  (typ-&gt;appendable,nrows-&gt;8,ncols-&gt;5,indexers-&gt;[index],dc-&gt;[B,C,string,string2])\n\/df_mi                     frame_table  (typ-&gt;appendable_multi,nrows-&gt;10,ncols-&gt;5,indexers-&gt;[index],dc-&gt;[bar,foo])    \n\/df_mixed                  frame_table  (typ-&gt;appendable,nrows-&gt;8,ncols-&gt;7,indexers-&gt;[index])                         \n\/p4d                       wide_table   (typ-&gt;appendable,nrows-&gt;40,ncols-&gt;1,indexers-&gt;[items,major_axis,minor_axis])  \n\/p4d2                      wide_table   (typ-&gt;appendable,nrows-&gt;20,ncols-&gt;2,indexers-&gt;[labels,major_axis,minor_axis]) \n\/wp                        wide_table   (typ-&gt;appendable,nrows-&gt;8,ncols-&gt;2,indexers-&gt;[major_axis,minor_axis])         \n\/wp_big_strings            wide_table   (typ-&gt;appendable,nrows-&gt;40,ncols-&gt;2,indexers-&gt;[major_axis,minor_axis])        \n\/foo\/bar\/bah               frame        (shape-&gt;[8,3])                                                                \n\nIn [1269]: store.select('p4d2', [ Term('labels=l1'), Term('items=Item1'), Term('minor_axis=A_big_strings') ])\nOut[1269]: \n&lt;class 'pandas.core.panelnd.Panel4D'&gt;\nDimensions: 1 (labels) x 1 (items) x 5 (major_axis) x 1 (minor_axis)\nLabels axis: l1 to l1\nItems axis: Item1 to Item1\nMajor_axis axis: 2000-01-01 00:00:00 to 2000-01-05 00:00:00\nMinor_axis axis: A_big_strings to A_big_strings<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div id=\"sql-queries\">\n<h2>SQL Queries<\/h2>\n<p>The\u00a0<tt>pandas.io.sql<\/tt>\u00a0module provides a collection of query wrappers to both facilitate data retrieval and to reduce dependency on DB-specific API. There wrappers only support the Python database adapters which respect the\u00a0<a href=\"http:\/\/www.python.org\/dev\/peps\/pep-0249\/\">Python DB-API<\/a>.<\/p>\n<p>See some\u00a0<a href=\"http:\/\/pandas.pydata.org\/pandas-docs\/dev\/cookbook.html#cookbook-sql\"><em>cookbook examples<\/em><\/a>\u00a0for some advanced strategies<\/p>\n<p>Suppose you want to query some data with different types from a table such as:<\/p>\n<table border=\"1\">\n<colgroup>\n<col width=\"13%\" \/>\n<col width=\"32%\" \/>\n<col width=\"18%\" \/>\n<col width=\"18%\" \/>\n<col width=\"18%\" \/><\/colgroup>\n<thead valign=\"bottom\">\n<tr>\n<th>id<\/th>\n<th>Date<\/th>\n<th>Col_1<\/th>\n<th>Col_2<\/th>\n<th>Col_3<\/th>\n<\/tr>\n<\/thead>\n<tbody valign=\"top\">\n<tr>\n<td>26<\/td>\n<td>2012-10-18<\/td>\n<td>X<\/td>\n<td>25.7<\/td>\n<td>True<\/td>\n<\/tr>\n<tr>\n<td>42<\/td>\n<td>2012-10-19<\/td>\n<td>Y<\/td>\n<td>-12.4<\/td>\n<td>False<\/td>\n<\/tr>\n<tr>\n<td>63<\/td>\n<td>2012-10-20<\/td>\n<td>Z<\/td>\n<td>5.73<\/td>\n<td>True<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Functions from\u00a0<tt>pandas.io.sql<\/tt>\u00a0can extract some data into a DataFrame. In the following example, we use\u00a0<a href=\"http:\/\/www.sqlite.org\/\">SQlite<\/a>\u00a0SQL database engine. You can use a temporary SQLite database where data are stored in \u201cmemory\u201d. Just do:<\/p>\n<div>\n<div>\n<pre>import sqlite3\nfrom pandas.io import sql\n# Create your connection.\ncnx = sqlite3.connect(':memory:')<\/pre>\n<\/div>\n<\/div>\n<p>Let\u00a0<tt>data<\/tt>\u00a0be the name of your SQL table. With a query and your database connection, just use the\u00a0<tt>read_frame()<\/tt>\u00a0function to get the query results into a DataFrame:<\/p>\n<div>\n<div>\n<pre>In [1270]: sql.read_frame(\"SELECT * FROM data;\", cnx)\nOut[1270]: \n   id                 date Col_1  Col_2  Col_3\n0  26  2010-10-18 00:00:00     X  27.50      1\n1  42  2010-10-19 00:00:00     Y -12.50      0\n2  63  2010-10-20 00:00:00     Z   5.73      1<\/pre>\n<\/div>\n<\/div>\n<p>You can also specify the name of the column as the DataFrame index:<\/p>\n<div>\n<div>\n<pre>In [1271]: sql.read_frame(\"SELECT * FROM data;\", cnx, index_col='id')\nOut[1271]: \n                   date Col_1  Col_2  Col_3\nid                                         \n26  2010-10-18 00:00:00     X  27.50      1\n42  2010-10-19 00:00:00     Y -12.50      0\n63  2010-10-20 00:00:00     Z   5.73      1\n\nIn [1272]: sql.read_frame(\"SELECT * FROM data;\", cnx, index_col='date')\nOut[1272]: \n                     id Col_1  Col_2  Col_3\ndate                                       \n2010-10-18 00:00:00  26     X  27.50      1\n2010-10-19 00:00:00  42     Y -12.50      0\n2010-10-20 00:00:00  63     Z   5.73      1<\/pre>\n<\/div>\n<\/div>\n<p>Of course, you can specify more \u201ccomplex\u201d query.<\/p>\n<div>\n<div>\n<pre>In [1273]: sql.read_frame(\"SELECT id, Col_1, Col_2 FROM data WHERE id = 42;\", cnx)\nOut[1273]: \n   id Col_1  Col_2\n0  42     Y  -12.5<\/pre>\n<\/div>\n<\/div>\n<p>There are a few other available functions:<\/p>\n<blockquote>\n<ul>\n<li><tt>tquery<\/tt>\u00a0returns list of tuples corresponding to each row.<\/li>\n<li><tt>uquery<\/tt>\u00a0does the same thing as tquery, but instead of returning results, it returns the number of related rows.<\/li>\n<li><tt>write_frame<\/tt>\u00a0writes records stored in a DataFrame into the SQL table.<\/li>\n<li><tt>has_table<\/tt>\u00a0checks if a given SQLite table exists.<\/li>\n<\/ul>\n<\/blockquote>\n<div>\n<p>Note<\/p>\n<p>For now, writing your DataFrame into a database works only with\u00a0<strong>SQLite<\/strong>. Moreover, the<strong>index<\/strong>\u00a0will currently be\u00a0<strong>dropped<\/strong>.<\/p>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>CSV &amp; Text files The two workhorse functions for reading text files (a.k.a. flat files) areread_csv()\u00a0and\u00a0read_table(). They both use the same parsing code to intelligently&hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[],"class_list":["post-133","post","type-post","status-publish","format-standard","hentry","category-python"],"_links":{"self":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts\/133","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/comments?post=133"}],"version-history":[{"count":0,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts\/133\/revisions"}],"wp:attachment":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/media?parent=133"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/categories?post=133"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/tags?post=133"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}