@@ -49,11 +49,11 @@ And then import the data directly to a DataFrame by calling:
49
49
50
50
clipdf
51
51
52
+ .. _io.read_csv_table :
53
+
52
54
CSV & Text files
53
55
----------------
54
56
55
- .. _io.parse_dates :
56
-
57
57
The two workhorse functions for reading text files (a.k.a. flat files) are
58
58
:func: `~pandas.io.parsers.read_csv ` and :func: `~pandas.io.parsers.read_table `.
59
59
They both use the same parsing code to intelligently convert tabular
@@ -118,9 +118,16 @@ The default for `read_csv` is to create a DataFrame with simple numbered rows:
118
118
read_csv(' foo.csv' )
119
119
120
120
In the case of indexed data, you can pass the column number (or a list of
121
- column numbers, for a hierarchical index) you wish to use as the index. If the
122
- index values are dates and you want them to be converted to ``datetime ``
123
- objects, pass ``parse_dates=True ``:
121
+ column numbers, for a hierarchical index) you wish to use as the index.
122
+
123
+ .. _io.parse_dates :
124
+
125
+ To better facilitate working with datetime data, :func: `~pandas.io.parsers.read_csv ` and :func: `~pandas.io.parsers.read_table `
126
+ uses the keyword arguments ``parse_dates `` and ``date_parser `` to allow users
127
+ to specify a variety of columns and date/time formats to turn the input text
128
+ data into ``datetime `` objects.
129
+
130
+ The simplest case is to just pass in ``parse_dates=True ``:
124
131
125
132
.. ipython :: python
126
133
@@ -135,6 +142,31 @@ objects, pass ``parse_dates=True``:
135
142
136
143
os.remove(' foo.csv' )
137
144
145
+ You can specify a custom ``date_parser `` function:
146
+
147
+ .. ipython :: python
148
+ :suppress:
149
+ # data = """
150
+ with open (' tmp.csv' , ' w' ) as fh:
151
+ fh.write(data)
152
+
153
+ .. ipython :: python
154
+
155
+ # read it in
156
+
157
+ .. ipython :: python
158
+ :suppress:
159
+ os.remove(' tmp.csv' )
160
+
161
+ It is often the case that we may want to store date and time data separately,
162
+ or store various date fields separately. the ``parse_dates `` keyword can be
163
+ used to specify a combination of columns to parse the dates and/or times from.
164
+
165
+ You can specify a list of column lists to ``parse_dates ``, the resulting date
166
+ columns will be prepended to the output and the new column names will be the
167
+ component column names
168
+
169
+
138
170
The parsers make every attempt to "do the right thing" and not be very
139
171
fragile. Type inference is a pretty big deal. So if a column can be coerced to
140
172
integer dtype without altering the contents, it will do so. Any non-numeric
0 commit comments