Skip to content

Commit 695e489

Browse files
sauravsaurav
saurav
authored and
saurav
committed
DOC: improve readibility and conformation to PEP-8 standards
1 parent 9e59499 commit 695e489

File tree

1 file changed

+74
-25
lines changed

1 file changed

+74
-25
lines changed

doc/source/io.rst

+74-25
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,10 @@ usecols : list-like or callable, default ``None``
145145

146146
.. ipython:: python
147147
148-
data = 'col1,col2,col3\na,b,1\na,b,2\nc,d,3'
148+
data = ('col1,col2,col3\n'
149+
'a,b,1\n'
150+
'a,b,2\n'
151+
'c,d,3')
149152
pd.read_csv(StringIO(data))
150153
pd.read_csv(StringIO(data), usecols=lambda x: x.upper() in ['COL1', 'COL3'])
151154
@@ -191,7 +194,10 @@ skiprows : list-like or integer, default ``None``
191194

192195
.. ipython:: python
193196
194-
data = 'col1,col2,col3\na,b,1\na,b,2\nc,d,3'
197+
data = ('col1,col2,col3\n'
198+
'a,b,1\n'
199+
'a,b,2\n'
200+
'c,d,3')
195201
pd.read_csv(StringIO(data))
196202
pd.read_csv(StringIO(data), skiprows=lambda x: x % 2 != 0)
197203
@@ -366,7 +372,10 @@ columns:
366372

367373
.. ipython:: python
368374
369-
data = 'a,b,c\n1,2,3\n4,5,6\n7,8,9'
375+
data = ('a,b,c\n'
376+
'1,2,3\n'
377+
'4,5,6\n'
378+
'7,8,9')
370379
print(data)
371380
372381
df = pd.read_csv(StringIO(data), dtype=object)
@@ -387,7 +396,11 @@ of :func:`~pandas.read_csv`:
387396

388397
.. ipython:: python
389398
390-
data = "col_1\n1\n2\n'A'\n4.22"
399+
data = ("col_1\n"
400+
"1\n"
401+
"2\n"
402+
"'A'\n"
403+
"4.22")
391404
df = pd.read_csv(StringIO(data), converters={'col_1': str})
392405
df
393406
df['col_1'].apply(type).value_counts()
@@ -455,7 +468,10 @@ Specifying Categorical dtype
455468

456469
.. ipython:: python
457470
458-
data = 'col1,col2,col3\na,b,1\na,b,2\nc,d,3'
471+
data = ('col1,col2,col3\n'
472+
'a,b,1\n'
473+
'a,b,2\n'
474+
'c,d,3')
459475
460476
pd.read_csv(StringIO(data))
461477
pd.read_csv(StringIO(data)).dtypes
@@ -524,7 +540,10 @@ used as the column names:
524540

525541
.. ipython:: python
526542
527-
data = 'a,b,c\n1,2,3\n4,5,6\n7,8,9'
543+
data = ('a,b,c\n'
544+
'1,2,3\n'
545+
'4,5,6\n'
546+
'7,8,9')
528547
print(data)
529548
pd.read_csv(StringIO(data))
530549
@@ -543,7 +562,11 @@ If the header is in a row other than the first, pass the row number to
543562

544563
.. ipython:: python
545564
546-
data = 'skip this skip it\na,b,c\n1,2,3\n4,5,6\n7,8,9'
565+
data = ('skip this skip it\n'
566+
'a,b,c\n'
567+
'1,2,3\n'
568+
'4,5,6\n'
569+
'7,8,9')
547570
pd.read_csv(StringIO(data), header=1)
548571
549572
.. note::
@@ -564,7 +587,9 @@ distinguish between them so as to prevent overwriting data:
564587

565588
.. ipython :: python
566589
567-
data = 'a,b,a\n0,1,2\n3,4,5'
590+
data = ('a,b,a\n'
591+
'0,1,2\n'
592+
'3,4,5')
568593
pd.read_csv(StringIO(data))
569594
570595
There is no more duplicate data because ``mangle_dupe_cols=True`` by default,
@@ -632,15 +657,26 @@ be ignored. By default, completely blank lines will be ignored as well.
632657

633658
.. ipython:: python
634659
635-
data = '\na,b,c\n \n# commented line\n1,2,3\n\n4,5,6'
660+
data = ('\n'
661+
'a,b,c\n'
662+
' \n'
663+
'# commented line\n'
664+
'1,2,3\n'
665+
'\n'
666+
'4,5,6')
636667
print(data)
637668
pd.read_csv(StringIO(data), comment='#')
638669
639670
If ``skip_blank_lines=False``, then ``read_csv`` will not ignore blank lines:
640671

641672
.. ipython:: python
642673
643-
data = 'a,b,c\n\n1,2,3\n\n\n4,5,6'
674+
data = ('a,b,c\n'
675+
'\n'
676+
'1,2,3\n'
677+
'\n'
678+
'\n'
679+
'4,5,6')
644680
pd.read_csv(StringIO(data), skip_blank_lines=False)
645681
646682
.. warning::
@@ -651,7 +687,10 @@ If ``skip_blank_lines=False``, then ``read_csv`` will not ignore blank lines:
651687

652688
.. ipython:: python
653689
654-
data = '#comment\na,b,c\nA,B,C\n1,2,3'
690+
data = ('#comment\n'
691+
'a,b,c\n'
692+
'A,B,C\n'
693+
'1,2,3')
655694
pd.read_csv(StringIO(data), comment='#', header=1)
656695
data = 'A,B,C\n#comment\na,b,c\n1,2,3'
657696
pd.read_csv(StringIO(data), comment='#', skiprows=2)
@@ -661,15 +700,14 @@ If ``skip_blank_lines=False``, then ``read_csv`` will not ignore blank lines:
661700

662701
.. ipython:: python
663702
664-
data = '\n'.join(['# empty',
665-
'# second empty line',
666-
'# third empty',
667-
'line',
668-
'X,Y,Z',
669-
'1,2,3',
670-
'A,B,C',
671-
'1,2.,4.',
672-
'5.,NaN,10.0'])
703+
data = ('# empty\n'
704+
'# second empty line\n'
705+
'# third emptyline\n'
706+
'X,Y,Z\n'
707+
'1,2,3\n'
708+
'A,B,C\n'
709+
'1,2.,4.\n'
710+
'5.,NaN,10.0\n')
673711
print(data)
674712
pd.read_csv(StringIO(data), comment='#', skiprows=4, header=1)
675713
@@ -724,7 +762,9 @@ result in byte strings being decoded to unicode in the result:
724762

725763
.. ipython:: python
726764
727-
data = b'word,length\nTr\xc3\xa4umen,7\nGr\xc3\xbc\xc3\x9fe,5'
765+
data = (b'word,length\n'
766+
b'Tr\xc3\xa4umen,7\n'
767+
b'Gr\xc3\xbc\xc3\x9fe,5')
728768
data = data.decode('utf8').encode('latin-1')
729769
df = pd.read_csv(BytesIO(data), encoding='latin-1')
730770
df
@@ -745,12 +785,16 @@ first column will be used as the ``DataFrame``'s row names:
745785

746786
.. ipython:: python
747787
748-
data = 'a,b,c\n4,apple,bat,5.7\n8,orange,cow,10'
788+
data = ('a,b,c\n'
789+
'4,apple,bat,5.7\n'
790+
'8,orange,cow,10')
749791
pd.read_csv(StringIO(data))
750792
751793
.. ipython:: python
752794
753-
data = 'index,a,b,c\n4,apple,bat,5.7\n8,orange,cow,10'
795+
data = ('index,a,b,c\n'
796+
'4,apple,bat,5.7\n'
797+
'8,orange,cow,10')
754798
pd.read_csv(StringIO(data), index_col=0)
755799
756800
Ordinarily, you can achieve this behavior using the ``index_col`` option.
@@ -761,7 +805,9 @@ index column inference and discard the last column, pass ``index_col=False``:
761805

762806
.. ipython:: python
763807
764-
data = 'a,b,c\n4,apple,bat,\n8,orange,cow,'
808+
data = ('a,b,c\n'
809+
'4,apple,bat,\n'
810+
'8,orange,cow,')
765811
print(data)
766812
pd.read_csv(StringIO(data))
767813
pd.read_csv(StringIO(data), index_col=False)
@@ -771,7 +817,9 @@ If a subset of data is being parsed using the ``usecols`` option, the
771817

772818
.. ipython:: python
773819
774-
data = 'a,b,c\n4,apple,bat,\n8,orange,cow,'
820+
data = ('a,b,c\n'
821+
'4,apple,bat,\n'
822+
'8,orange,cow,')
775823
print(data)
776824
pd.read_csv(StringIO(data), usecols=['b', 'c'])
777825
pd.read_csv(StringIO(data), usecols=['b', 'c'], index_col=0)
@@ -5451,6 +5499,7 @@ And here's the code:
54515499
sz = 1000000
54525500
df = pd.DataFrame({'A': randn(sz), 'B': [1] * sz})
54535501
5502+
54545503
def test_sql_write(df):
54555504
if os.path.exists('test.sql'):
54565505
os.remove('test.sql')

0 commit comments

Comments
 (0)