Skip to content

Commit 2cc6bfa

Browse files
authored
DOC: Clean up CSV sniffing and chunking examples (#53987)
1 parent 15cef2c commit 2cc6bfa

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

doc/source/user_guide/io.rst

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,8 +1568,7 @@ class of the csv module. For this, you have to specify ``sep=None``.
15681568
.. ipython:: python
15691569
15701570
df = pd.DataFrame(np.random.randn(10, 4))
1571-
df.to_csv("tmp.csv", sep="|")
1572-
df.to_csv("tmp2.csv", sep=":")
1571+
df.to_csv("tmp2.csv", sep=":", index=False)
15731572
pd.read_csv("tmp2.csv", sep=None, engine="python")
15741573
15751574
.. ipython:: python
@@ -1597,8 +1596,8 @@ rather than reading the entire file into memory, such as the following:
15971596
.. ipython:: python
15981597
15991598
df = pd.DataFrame(np.random.randn(10, 4))
1600-
df.to_csv("tmp.csv", sep="|")
1601-
table = pd.read_csv("tmp.csv", sep="|")
1599+
df.to_csv("tmp.csv", index=False)
1600+
table = pd.read_csv("tmp.csv")
16021601
table
16031602
16041603
@@ -1607,8 +1606,8 @@ value will be an iterable object of type ``TextFileReader``:
16071606

16081607
.. ipython:: python
16091608
1610-
with pd.read_csv("tmp.csv", sep="|", chunksize=4) as reader:
1611-
reader
1609+
with pd.read_csv("tmp.csv", chunksize=4) as reader:
1610+
print(reader)
16121611
for chunk in reader:
16131612
print(chunk)
16141613
@@ -1620,8 +1619,8 @@ Specifying ``iterator=True`` will also return the ``TextFileReader`` object:
16201619

16211620
.. ipython:: python
16221621
1623-
with pd.read_csv("tmp.csv", sep="|", iterator=True) as reader:
1624-
reader.get_chunk(5)
1622+
with pd.read_csv("tmp.csv", iterator=True) as reader:
1623+
print(reader.get_chunk(5))
16251624
16261625
.. ipython:: python
16271626
:suppress:

0 commit comments

Comments
 (0)