99 import csv
1010 from StringIO import StringIO
1111 import pandas as pd
12+ ExcelWriter = pd.ExcelWriter
1213
1314 import numpy as np
1415 np.random.seed(123456 )
2728IO Tools (Text, CSV, HDF5, ...)
2829*******************************
2930
31+ The Pandas I/O api is a set of top level ``reader `` functions accessed like ``pd.read_csv() `` that generally return a ``pandas ``
32+ object. The corresponding ``writer `` functions are object methods that are accessed like ``df.to_csv() ``
33+
34+ .. csv-table ::
35+ :widths: 12, 15, 15, 15, 15
36+ :delim: ;
37+
38+ Reader; ``read_csv ``; ``read_excel ``; ``read_hdf ``; ``read_sql ``
39+ Writer; ``to_csv ``; ``to_excel ``; ``to_hdf ``; ``to_sql ``
40+ Reader; ``read_html ``; ``read_stata ``; ``read_clipboard `` ;
41+ Writer; ``to_html ``; ``to_stata ``; ``to_clipboard `` ;
42+
3043.. _io.read_csv_table :
3144
3245CSV & Text files
@@ -971,44 +984,48 @@ And then import the data directly to a DataFrame by calling:
971984Excel files
972985-----------
973986
974- The ``ExcelFile `` class can read an Excel 2003 file using the ``xlrd `` Python
987+ The ``read_excel `` method can read an Excel 2003 file using the ``xlrd `` Python
975988module and use the same parsing code as the above to convert tabular data into
976989a DataFrame. See the :ref: `cookbook<cookbook.excel> ` for some
977990advanced strategies
978991
979- To use it, create the `` ExcelFile `` object :
992+ .. note : :
980993
981- .. code-block :: python
994+ The prior method of accessing Excel is now deprecated as of 0.11.1,
995+ this will work but will be removed in a future version.
982996
983- xls = ExcelFile( ' path_to_file.xls ' )
997+ .. code-block :: python
984998
985- Then use the ``parse `` instance method with a sheetname, then use the same
986- additional arguments as the parsers above:
999+ from pandas.io.parsers import ExcelFile
1000+ xls = ExcelFile(' path_to_file.xls' )
1001+ xls.parse(' Sheet1' , index_col = None , na_values = [' NA' ])
9871002
988- .. code-block :: python
1003+ Replaced by
1004+
1005+ .. code-block :: python
9891006
990- xls.parse( ' Sheet1' , index_col = None , na_values = [' NA' ])
1007+ read_excel( ' path_to_file.xls ' , ' Sheet1' , index_col = None , na_values = [' NA' ])
9911008
9921009 To read sheets from an Excel 2007 file, you can pass a filename with a ``.xlsx ``
9931010extension, in which case the ``openpyxl `` module will be used to read the file.
9941011
9951012It is often the case that users will insert columns to do temporary computations
996- in Excel and you may not want to read in those columns. `ExcelFile.parse ` takes
1013+ in Excel and you may not want to read in those columns. `read_excel ` takes
9971014a `parse_cols ` keyword to allow you to specify a subset of columns to parse.
9981015
9991016If `parse_cols ` is an integer, then it is assumed to indicate the last column
10001017to be parsed.
10011018
10021019.. code-block :: python
10031020
1004- xls.parse( ' Sheet1' , parse_cols = 2 , index_col = None , na_values = [' NA' ])
1021+ read_excel( ' path_to_file.xls ' , ' Sheet1' , parse_cols = 2 , index_col = None , na_values = [' NA' ])
10051022
10061023 If `parse_cols ` is a list of integers, then it is assumed to be the file column
10071024indices to be parsed.
10081025
10091026.. code-block :: python
10101027
1011- xls.parse( ' Sheet1' , parse_cols = [0 , 2 , 3 ], index_col = None , na_values = [' NA' ])
1028+ read_excel( ' path_to_file.xls ' , Sheet1' , parse_cols=[0, 2, 3], index_col=None, na_values=[' NA ' ])
10121029
10131030To write a DataFrame object to a sheet of an Excel file , you can use the
10141031`` to_excel`` instance method. The arguments are largely the same as `` to_csv``
@@ -1883,16 +1900,13 @@ Writing to STATA format
18831900
18841901.. _io.StataWriter:
18851902
1886- The function :func: '~pandas.io.StataWriter.write_file' will write a DataFrame
1887- into a .dta file. The format version of this file is always the latest one,
1888- 115.
1903+ The method `` to_stata`` will write a DataFrame into a .dta file .
1904+ The format version of this file is always the latest one, 115 .
18891905
18901906.. ipython:: python
18911907
1892- from pandas.io.stata import StataWriter
18931908 df = DataFrame(randn(10 ,2 ),columns = list (' AB' ))
1894- writer = StataWriter(' stata.dta' ,df)
1895- writer.write_file()
1909+ df.to_stata(' stata.dta' )
18961910
18971911Reading from STATA format
18981912~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -1901,24 +1915,21 @@ Reading from STATA format
19011915
19021916.. versionadded:: 0.11 .1
19031917
1904- The class StataReader will read the header of the given dta file at
1905- initialization. Its function :func: '~pandas.io.StataReader.data' will
1906- read the observations, converting them to a DataFrame which is returned:
1918+ The top- level function `` read_stata`` will read a dta format file
1919+ and return a DataFrame:
19071920
19081921.. ipython:: python
19091922
1910- from pandas.io.stata import StataReader
1911- reader = StataReader(' stata.dta' )
1912- reader.data()
1923+ pd.read_stata(' stata.dta' )
19131924
1914- The parameter convert_categoricals indicates wheter value labels should be
1915- read and used to create a Categorical variable from them. Value labels can
1916- also be retrieved by the function variable_labels, which requires data to be
1917- called before.
1925+ Currently the `` index`` is retrieved as a column on read back.
19181926
1919- The StataReader supports .dta Formats 104, 105, 108, 113-115.
1927+ The parameter `` convert_categoricals`` indicates wheter value labels should be
1928+ read and used to create a `` Categorical`` variable from them. Value labels can
1929+ also be retrieved by the function `` variable_labels`` , which requires data to be
1930+ called before (see `` pandas.io.stata.StataReader`` ).
19201931
1921- Alternatively, the function :func: '~pandas.io.read_stata' can be used
1932+ The StataReader supports .dta Formats 104 , 105 , 108 , 113 - 115 .
19221933
19231934.. ipython:: python
19241935 :suppress:
0 commit comments