Skip to content

Commit d09ca7d

Browse files
committed
DOC: read_fwf doc tweaks for 0.7.3
1 parent e71e89a commit d09ca7d

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

doc/source/io.rst

+12-10
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,10 @@ fragile. Type inference is a pretty big deal. So if a column can be coerced to
139139
integer dtype without altering the contents, it will do so. Any non-numeric
140140
columns will come through as object dtype as with the rest of pandas objects.
141141

142+
.. _io.fwf:
143+
142144
Files with Fixed Width Columns
143-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
145+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
144146
While `read_csv` reads delimited data, the :func:`~pandas.io.parsers.read_fwf`
145147
function works with data files that have known and fixed column widths.
146148
The function parameters to `read_fwf` are largely the same as `read_csv` with
@@ -155,13 +157,11 @@ two extra parameters:
155157
:suppress:
156158
157159
f = open('bar.csv', 'w')
158-
data1 = """\
159-
id8141 360.242940 149.910199 11950.7
160-
id1594 444.953632 166.985655 11788.4
161-
id1849 364.136849 183.628767 11806.2
162-
id1230 413.836124 184.375703 11916.8
163-
id1948 502.953953 173.237159 12468.3
164-
"""
160+
data1 = ("id8141 360.242940 149.910199 11950.7\n"
161+
"id1594 444.953632 166.985655 11788.4\n"
162+
"id1849 364.136849 183.628767 11806.2\n"
163+
"id1230 413.836124 184.375703 11916.8\n"
164+
"id1948 502.953953 173.237159 12468.3")
165165
f.write(data1)
166166
f.close()
167167
@@ -181,13 +181,15 @@ column specifications to the `read_fwf` function along with the file name:
181181
df = read_fwf('bar.csv', colspecs=colspecs, header=None, index_col=0)
182182
df
183183
184-
Alternatively, you can supply just the column widths for contiguous columns:
184+
Note how the parser automatically picks column names X.<column number> when
185+
``header=None`` argument is specified. Alternatively, you can supply just the
186+
column widths for contiguous columns:
185187

186188
.. ipython:: python
187189
188190
#Widths are a list of integers
189191
widths = [6, 14, 13, 10]
190-
df = read_fwf('bar.csv', widths=widths, header=None, index_col=0)
192+
df = read_fwf('bar.csv', widths=widths, header=None)
191193
df
192194
193195
The parser will take care of extra white spaces around the columns

doc/source/whatsnew/v0.7.3.txt

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ or issue tracker on GitHub for a complete list.
1212
New features
1313
~~~~~~~~~~~~
1414

15-
- New fixed width file reader, ``read_fwf``
16-
- New :ref:`scatter_matrix <visualization.scatter_matrix>` function
15+
- New :ref:`fixed width file reader <io.fwf>`, ``read_fwf``
16+
- New :ref:`scatter_matrix <visualization.scatter_matrix>` function for making
17+
a scatter plot matrix
1718

1819
.. code-block:: python
1920

0 commit comments

Comments
 (0)