Skip to content

Commit bd804aa

Browse files
Merge pull request #10163 from jorisvandenbossche/depr-from_csv
DOC: clarify purpose of DataFrame.from_csv (GH4191)
2 parents 32e60d7 + d2ce36a commit bd804aa

File tree

2 files changed

+46
-11
lines changed

2 files changed

+46
-11
lines changed

pandas/core/frame.py

+22-8
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ class DataFrame(NDFrame):
180180
--------
181181
DataFrame.from_records : constructor from tuples, also record arrays
182182
DataFrame.from_dict : from dicts of Series, arrays, or dicts
183-
DataFrame.from_csv : from CSV files
184183
DataFrame.from_items : from sequence of (key, value) pairs
185184
pandas.read_csv, pandas.read_table, pandas.read_clipboard
186185
"""
@@ -1059,13 +1058,29 @@ def from_csv(cls, path, header=0, sep=',', index_col=0,
10591058
parse_dates=True, encoding=None, tupleize_cols=False,
10601059
infer_datetime_format=False):
10611060
"""
1062-
Read delimited file into DataFrame
1061+
Read CSV file (DISCOURAGED, please use :func:`pandas.read_csv` instead).
1062+
1063+
It is preferable to use the more powerful :func:`pandas.read_csv`
1064+
for most general purposes, but ``from_csv`` makes for an easy
1065+
roundtrip to and from a file (the exact counterpart of
1066+
``to_csv``), especially with a DataFrame of time series data.
1067+
1068+
This method only differs from the preferred :func:`pandas.read_csv`
1069+
in some defaults:
1070+
1071+
- `index_col` is ``0`` instead of ``None`` (take first column as index
1072+
by default)
1073+
- `parse_dates` is ``True`` instead of ``False`` (try parsing the index
1074+
as datetime by default)
1075+
1076+
So a ``pd.DataFrame.from_csv(path)`` can be replaced by
1077+
``pd.read_csv(path, index_col=0, parse_dates=True)``.
10631078
10641079
Parameters
10651080
----------
10661081
path : string file path or file handle / StringIO
10671082
header : int, default 0
1068-
Row to use at header (skip prior rows)
1083+
Row to use as header (skip prior rows)
10691084
sep : string, default ','
10701085
Field delimiter
10711086
index_col : int or sequence, default 0
@@ -1081,15 +1096,14 @@ def from_csv(cls, path, header=0, sep=',', index_col=0,
10811096
datetime format based on the first datetime string. If the format
10821097
can be inferred, there often will be a large parsing speed-up.
10831098
1084-
Notes
1085-
-----
1086-
Preferable to use read_table for most general purposes but from_csv
1087-
makes for an easy roundtrip to and from file, especially with a
1088-
DataFrame of time series data
1099+
See also
1100+
--------
1101+
pandas.read_csv
10891102
10901103
Returns
10911104
-------
10921105
y : DataFrame
1106+
10931107
"""
10941108
from pandas.io.parsers import read_table
10951109
return read_table(path, header=header, sep=sep,

pandas/core/series.py

+24-3
Original file line numberDiff line numberDiff line change
@@ -2317,7 +2317,24 @@ def between(self, left, right, inclusive=True):
23172317
def from_csv(cls, path, sep=',', parse_dates=True, header=None,
23182318
index_col=0, encoding=None, infer_datetime_format=False):
23192319
"""
2320-
Read delimited file into Series
2320+
Read CSV file (DISCOURAGED, please use :func:`pandas.read_csv` instead).
2321+
2322+
It is preferable to use the more powerful :func:`pandas.read_csv`
2323+
for most general purposes, but ``from_csv`` makes for an easy
2324+
roundtrip to and from a file (the exact counterpart of
2325+
``to_csv``), especially with a time Series.
2326+
2327+
This method only differs from :func:`pandas.read_csv` in some defaults:
2328+
2329+
- `index_col` is ``0`` instead of ``None`` (take first column as index
2330+
by default)
2331+
- `header` is ``None`` instead of ``0`` (the first row is not used as
2332+
the column names)
2333+
- `parse_dates` is ``True`` instead of ``False`` (try parsing the index
2334+
as datetime by default)
2335+
2336+
With :func:`pandas.read_csv`, the option ``squeeze=True`` can be used
2337+
to return a Series like ``from_csv``.
23212338
23222339
Parameters
23232340
----------
@@ -2326,8 +2343,8 @@ def from_csv(cls, path, sep=',', parse_dates=True, header=None,
23262343
Field delimiter
23272344
parse_dates : boolean, default True
23282345
Parse dates. Different default from read_table
2329-
header : int, default 0
2330-
Row to use at header (skip prior rows)
2346+
header : int, default None
2347+
Row to use as header (skip prior rows)
23312348
index_col : int or sequence, default 0
23322349
Column to use for index. If a sequence is given, a MultiIndex
23332350
is used. Different default from read_table
@@ -2339,6 +2356,10 @@ def from_csv(cls, path, sep=',', parse_dates=True, header=None,
23392356
datetime format based on the first datetime string. If the format
23402357
can be inferred, there often will be a large parsing speed-up.
23412358
2359+
See also
2360+
--------
2361+
pandas.read_csv
2362+
23422363
Returns
23432364
-------
23442365
y : Series

0 commit comments

Comments
 (0)