Skip to content

Commit ad88cd9

Browse files
committed
ENH: pandas read_* wildcard pandas-dev#15904
1 parent b2a4f72 commit ad88cd9

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

doc/source/cookbook.rst

+5-9
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,7 @@ Reading multiple files to create a single DataFrame
946946
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
947947

948948
The best way to combine multiple files into a single DataFrame is to read the individual frames one by one, put all
949-
of the individual frames into a list, and then combine the frames in the list using ``pd.concat``:
949+
of the individual frames into a list, and then combine the frames in the list using :func:`pd.concat`:
950950

951951
.. ipython:: python
952952
@@ -956,22 +956,18 @@ of the individual frames into a list, and then combine the frames in the list us
956956
957957
frames = []
958958
files = ['file_0.csv', 'file_1.csv', 'file_2.csv']
959-
for f in files:
960-
frames.append(pd.read_csv(f))
961-
result = pd.concat(frames)
959+
result = pd.concat([pd.read_csv(f) for f in files], ignore_index=True)
962960
963961
You can use the same approach to read all files matching a pattern. Here is an example using ``glob``:
964962

965963
.. ipython:: python
966964
967965
import glob
968966
frames = []
969-
for f in glob.glob('file_*.csv'):
970-
frames.append(pd.read_csv(f))
971-
result = pd.concat(frames)
967+
files = glob.glob('file_*.csv')
968+
result = pd.concat([pd.read_csv(f) for f in files], ignore_index=True)
972969
973-
This performs significantly better than using ``pd.append`` to add each of the files to an existing DataFrame.
974-
Finally, this strategy will work with the other ``read_`` functions described in the :ref:`io docs<io>`.
970+
Finally, this strategy will work with the other ``read_*(...)`` functions described in the :ref:`io docs<io>`.
975971

976972
.. ipython:: python
977973
:supress:

doc/source/io.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1444,7 +1444,7 @@ class of the csv module. For this, you have to specify ``sep=None``.
14441444
Reading multiple files to create a single DataFrame
14451445
'''''''''''''''''''''''''''''''''''''''''''''''''''
14461446

1447-
It's best to use ``pd.concat`` to combine multiple files, rather than ``pd.append``.
1447+
It's best to use :func:`~pandas.concat` to combine multiple files.
14481448
See the :ref:`cookbook<cookbook.csv.multiple_files>` for an example.
14491449

14501450
.. _io.chunking:

0 commit comments

Comments
 (0)