Skip to content

Commit 2fe8363

Browse files
beananKevin D Smith
beanan
authored and
Kevin D Smith
committed
DOC: black enhancingperf.rst and 10min.rst code style (pandas-dev#36849)
1 parent 582a020 commit 2fe8363

File tree

3 files changed

+124
-121
lines changed

3 files changed

+124
-121
lines changed

doc/source/user_guide/10min.rst

+51-50
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ and labeled columns:
3434

3535
.. ipython:: python
3636
37-
dates = pd.date_range('20130101', periods=6)
37+
dates = pd.date_range("20130101", periods=6)
3838
dates
39-
df = pd.DataFrame(np.random.randn(6, 4), index=dates, columns=list('ABCD'))
39+
df = pd.DataFrame(np.random.randn(6, 4), index=dates, columns=list("ABCD"))
4040
df
4141
4242
Creating a :class:`DataFrame` by passing a dict of objects that can be converted to series-like.
@@ -156,7 +156,7 @@ Sorting by values:
156156

157157
.. ipython:: python
158158
159-
df.sort_values(by='B')
159+
df.sort_values(by="B")
160160
161161
Selection
162162
---------
@@ -178,14 +178,14 @@ equivalent to ``df.A``:
178178

179179
.. ipython:: python
180180
181-
df['A']
181+
df["A"]
182182
183183
Selecting via ``[]``, which slices the rows.
184184

185185
.. ipython:: python
186186
187187
df[0:3]
188-
df['20130102':'20130104']
188+
df["20130102":"20130104"]
189189
190190
Selection by label
191191
~~~~~~~~~~~~~~~~~~
@@ -202,31 +202,31 @@ Selecting on a multi-axis by label:
202202

203203
.. ipython:: python
204204
205-
df.loc[:, ['A', 'B']]
205+
df.loc[:, ["A", "B"]]
206206
207207
Showing label slicing, both endpoints are *included*:
208208

209209
.. ipython:: python
210210
211-
df.loc['20130102':'20130104', ['A', 'B']]
211+
df.loc["20130102":"20130104", ["A", "B"]]
212212
213213
Reduction in the dimensions of the returned object:
214214

215215
.. ipython:: python
216216
217-
df.loc['20130102', ['A', 'B']]
217+
df.loc["20130102", ["A", "B"]]
218218
219219
For getting a scalar value:
220220

221221
.. ipython:: python
222222
223-
df.loc[dates[0], 'A']
223+
df.loc[dates[0], "A"]
224224
225225
For getting fast access to a scalar (equivalent to the prior method):
226226

227227
.. ipython:: python
228228
229-
df.at[dates[0], 'A']
229+
df.at[dates[0], "A"]
230230
231231
Selection by position
232232
~~~~~~~~~~~~~~~~~~~~~
@@ -282,7 +282,7 @@ Using a single column's values to select data.
282282

283283
.. ipython:: python
284284
285-
df[df['A'] > 0]
285+
df[df["A"] > 0]
286286
287287
Selecting values from a DataFrame where a boolean condition is met.
288288

@@ -295,9 +295,9 @@ Using the :func:`~Series.isin` method for filtering:
295295
.. ipython:: python
296296
297297
df2 = df.copy()
298-
df2['E'] = ['one', 'one', 'two', 'three', 'four', 'three']
298+
df2["E"] = ["one", "one", "two", "three", "four", "three"]
299299
df2
300-
df2[df2['E'].isin(['two', 'four'])]
300+
df2[df2["E"].isin(["two", "four"])]
301301
302302
Setting
303303
~~~~~~~
@@ -307,15 +307,15 @@ by the indexes.
307307

308308
.. ipython:: python
309309
310-
s1 = pd.Series([1, 2, 3, 4, 5, 6], index=pd.date_range('20130102', periods=6))
310+
s1 = pd.Series([1, 2, 3, 4, 5, 6], index=pd.date_range("20130102", periods=6))
311311
s1
312-
df['F'] = s1
312+
df["F"] = s1
313313
314314
Setting values by label:
315315

316316
.. ipython:: python
317317
318-
df.at[dates[0], 'A'] = 0
318+
df.at[dates[0], "A"] = 0
319319
320320
Setting values by position:
321321

@@ -327,7 +327,7 @@ Setting by assigning with a NumPy array:
327327

328328
.. ipython:: python
329329
330-
df.loc[:, 'D'] = np.array([5] * len(df))
330+
df.loc[:, "D"] = np.array([5] * len(df))
331331
332332
The result of the prior setting operations.
333333

@@ -356,15 +356,15 @@ returns a copy of the data.
356356

357357
.. ipython:: python
358358
359-
df1 = df.reindex(index=dates[0:4], columns=list(df.columns) + ['E'])
360-
df1.loc[dates[0]:dates[1], 'E'] = 1
359+
df1 = df.reindex(index=dates[0:4], columns=list(df.columns) + ["E"])
360+
df1.loc[dates[0] : dates[1], "E"] = 1
361361
df1
362362
363363
To drop any rows that have missing data.
364364

365365
.. ipython:: python
366366
367-
df1.dropna(how='any')
367+
df1.dropna(how="any")
368368
369369
Filling missing data.
370370

@@ -408,7 +408,7 @@ In addition, pandas automatically broadcasts along the specified dimension.
408408
409409
s = pd.Series([1, 3, 5, np.nan, 6, 8], index=dates).shift(2)
410410
s
411-
df.sub(s, axis='index')
411+
df.sub(s, axis="index")
412412
413413
414414
Apply
@@ -444,7 +444,7 @@ some cases always uses them). See more at :ref:`Vectorized String Methods
444444

445445
.. ipython:: python
446446
447-
s = pd.Series(['A', 'B', 'C', 'Aaba', 'Baca', np.nan, 'CABA', 'dog', 'cat'])
447+
s = pd.Series(["A", "B", "C", "Aaba", "Baca", np.nan, "CABA", "dog", "cat"])
448448
s.str.lower()
449449
450450
Merge
@@ -486,21 +486,21 @@ SQL style merges. See the :ref:`Database style joining <merging.join>` section.
486486

487487
.. ipython:: python
488488
489-
left = pd.DataFrame({'key': ['foo', 'foo'], 'lval': [1, 2]})
490-
right = pd.DataFrame({'key': ['foo', 'foo'], 'rval': [4, 5]})
489+
left = pd.DataFrame({"key": ["foo", "foo"], "lval": [1, 2]})
490+
right = pd.DataFrame({"key": ["foo", "foo"], "rval": [4, 5]})
491491
left
492492
right
493-
pd.merge(left, right, on='key')
493+
pd.merge(left, right, on="key")
494494
495495
Another example that can be given is:
496496

497497
.. ipython:: python
498498
499-
left = pd.DataFrame({'key': ['foo', 'bar'], 'lval': [1, 2]})
500-
right = pd.DataFrame({'key': ['foo', 'bar'], 'rval': [4, 5]})
499+
left = pd.DataFrame({"key": ["foo", "bar"], "lval": [1, 2]})
500+
right = pd.DataFrame({"key": ["foo", "bar"], "rval": [4, 5]})
501501
left
502502
right
503-
pd.merge(left, right, on='key')
503+
pd.merge(left, right, on="key")
504504
505505
Grouping
506506
--------
@@ -531,14 +531,14 @@ groups.
531531

532532
.. ipython:: python
533533
534-
df.groupby('A').sum()
534+
df.groupby("A").sum()
535535
536536
Grouping by multiple columns forms a hierarchical index, and again we can
537537
apply the :meth:`~pandas.core.groupby.GroupBy.sum` function.
538538

539539
.. ipython:: python
540540
541-
df.groupby(['A', 'B']).sum()
541+
df.groupby(["A", "B"]).sum()
542542
543543
Reshaping
544544
---------
@@ -559,8 +559,8 @@ Stack
559559
]
560560
)
561561
)
562-
index = pd.MultiIndex.from_tuples(tuples, names=['first', 'second'])
563-
df = pd.DataFrame(np.random.randn(8, 2), index=index, columns=['A', 'B'])
562+
index = pd.MultiIndex.from_tuples(tuples, names=["first", "second"])
563+
df = pd.DataFrame(np.random.randn(8, 2), index=index, columns=["A", "B"])
564564
df2 = df[:4]
565565
df2
566566
@@ -603,7 +603,7 @@ We can produce pivot tables from this data very easily:
603603

604604
.. ipython:: python
605605
606-
pd.pivot_table(df, values='D', index=['A', 'B'], columns=['C'])
606+
pd.pivot_table(df, values="D", index=["A", "B"], columns=["C"])
607607
608608
609609
Time series
@@ -616,31 +616,31 @@ financial applications. See the :ref:`Time Series section <timeseries>`.
616616

617617
.. ipython:: python
618618
619-
rng = pd.date_range('1/1/2012', periods=100, freq='S')
619+
rng = pd.date_range("1/1/2012", periods=100, freq="S")
620620
ts = pd.Series(np.random.randint(0, 500, len(rng)), index=rng)
621-
ts.resample('5Min').sum()
621+
ts.resample("5Min").sum()
622622
623623
Time zone representation:
624624

625625
.. ipython:: python
626626
627-
rng = pd.date_range('3/6/2012 00:00', periods=5, freq='D')
627+
rng = pd.date_range("3/6/2012 00:00", periods=5, freq="D")
628628
ts = pd.Series(np.random.randn(len(rng)), rng)
629629
ts
630-
ts_utc = ts.tz_localize('UTC')
630+
ts_utc = ts.tz_localize("UTC")
631631
ts_utc
632632
633633
Converting to another time zone:
634634

635635
.. ipython:: python
636636
637-
ts_utc.tz_convert('US/Eastern')
637+
ts_utc.tz_convert("US/Eastern")
638638
639639
Converting between time span representations:
640640

641641
.. ipython:: python
642642
643-
rng = pd.date_range('1/1/2012', periods=5, freq='M')
643+
rng = pd.date_range("1/1/2012", periods=5, freq="M")
644644
ts = pd.Series(np.random.randn(len(rng)), index=rng)
645645
ts
646646
ps = ts.to_period()
@@ -654,9 +654,9 @@ the quarter end:
654654

655655
.. ipython:: python
656656
657-
prng = pd.period_range('1990Q1', '2000Q4', freq='Q-NOV')
657+
prng = pd.period_range("1990Q1", "2000Q4", freq="Q-NOV")
658658
ts = pd.Series(np.random.randn(len(prng)), prng)
659-
ts.index = (prng.asfreq('M', 'e') + 1).asfreq('H', 's') + 9
659+
ts.index = (prng.asfreq("M", "e") + 1).asfreq("H", "s") + 9
660660
ts.head()
661661
662662
Categoricals
@@ -754,19 +754,20 @@ CSV
754754

755755
.. ipython:: python
756756
757-
df.to_csv('foo.csv')
757+
df.to_csv("foo.csv")
758758
759759
:ref:`Reading from a csv file. <io.read_csv_table>`
760760

761761
.. ipython:: python
762762
763-
pd.read_csv('foo.csv')
763+
pd.read_csv("foo.csv")
764764
765765
.. ipython:: python
766766
:suppress:
767767
768768
import os
769-
os.remove('foo.csv')
769+
770+
os.remove("foo.csv")
770771
771772
HDF5
772773
~~~~
@@ -777,18 +778,18 @@ Writing to a HDF5 Store.
777778

778779
.. ipython:: python
779780
780-
df.to_hdf('foo.h5', 'df')
781+
df.to_hdf("foo.h5", "df")
781782
782783
Reading from a HDF5 Store.
783784

784785
.. ipython:: python
785786
786-
pd.read_hdf('foo.h5', 'df')
787+
pd.read_hdf("foo.h5", "df")
787788
788789
.. ipython:: python
789790
:suppress:
790791
791-
os.remove('foo.h5')
792+
os.remove("foo.h5")
792793
793794
Excel
794795
~~~~~
@@ -799,18 +800,18 @@ Writing to an excel file.
799800

800801
.. ipython:: python
801802
802-
df.to_excel('foo.xlsx', sheet_name='Sheet1')
803+
df.to_excel("foo.xlsx", sheet_name="Sheet1")
803804
804805
Reading from an excel file.
805806

806807
.. ipython:: python
807808
808-
pd.read_excel('foo.xlsx', 'Sheet1', index_col=None, na_values=['NA'])
809+
pd.read_excel("foo.xlsx", "Sheet1", index_col=None, na_values=["NA"])
809810
810811
.. ipython:: python
811812
:suppress:
812813
813-
os.remove('foo.xlsx')
814+
os.remove("foo.xlsx")
814815
815816
Gotchas
816817
-------

0 commit comments

Comments
 (0)