Skip to content

DOC: Fix PEP-8 issues in 10min.rst #23908

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 27, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 38 additions & 39 deletions doc/source/10min.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,6 @@

.. currentmodule:: pandas

.. ipython:: python
:suppress:

import numpy as np
import pandas as pd
import os
np.random.seed(123456)
np.set_printoptions(precision=4, suppress=True)
import matplotlib
# matplotlib.style.use('default')
pd.options.display.max_rows = 15

#### portions of this were borrowed from the
#### Pandas cheatsheet
#### created during the PyData Workshop-Sprint 2012
#### Hannah Chen, Henry Chow, Eric Cox, Robert Mauriello


********************
10 Minutes to pandas
Expand All @@ -31,9 +14,22 @@ Customarily, we import as follows:

.. ipython:: python

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

.. ipython:: python
:suppress:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not at the beginning and with numpy and pandas imports in the same suppress block? I think this is what we do in all the other pages, right?


import os

np.random.seed(123456)
np.set_printoptions(precision=4, suppress=True)
pd.options.display.max_rows = 15

# portions of this were borrowed from the
# Pandas cheatsheet
# created during the PyData Workshop-Sprint 2012
# Hannah Chen, Henry Chow, Eric Cox, Robert Mauriello

Object Creation
---------------
Expand All @@ -55,7 +51,7 @@ and labeled columns:

dates = pd.date_range('20130101', periods=6)
dates
df = pd.DataFrame(np.random.randn(6,4), index=dates, columns=list('ABCD'))
df = pd.DataFrame(np.random.randn(6, 4), index=dates, columns=list('ABCD'))
df

Creating a ``DataFrame`` by passing a dict of objects that can be converted to series-like.
Expand All @@ -64,7 +60,7 @@ Creating a ``DataFrame`` by passing a dict of objects that can be converted to s

df2 = pd.DataFrame({'A': 1.,
'B': pd.Timestamp('20130102'),
'C': pd.Series(1, index=list(range(4)),dtype='float32'),
'C': pd.Series(1, index=list(range(4)), dtype='float32'),
'D': np.array([3] * 4, dtype='int32'),
'E': pd.Categorical(["test", "train", "test", "train"]),
'F': 'foo'})
Expand Down Expand Up @@ -190,31 +186,31 @@ Selecting on a multi-axis by label:

.. ipython:: python

df.loc[:,['A','B']]
df.loc[:, ['A', 'B']]

Showing label slicing, both endpoints are *included*:

.. ipython:: python

df.loc['20130102':'20130104',['A','B']]
df.loc['20130102':'20130104', ['A', 'B']]

Reduction in the dimensions of the returned object:

.. ipython:: python

df.loc['20130102',['A','B']]
df.loc['20130102', ['A', 'B']]

For getting a scalar value:

.. ipython:: python

df.loc[dates[0],'A']
df.loc[dates[0], 'A']

For getting fast access to a scalar (equivalent to the prior method):

.. ipython:: python

df.at[dates[0],'A']
df.at[dates[0], 'A']

Selection by Position
~~~~~~~~~~~~~~~~~~~~~
Expand All @@ -231,37 +227,37 @@ By integer slices, acting similar to numpy/python:

.. ipython:: python

df.iloc[3:5,0:2]
df.iloc[3:5, 0:2]

By lists of integer position locations, similar to the numpy/python style:

.. ipython:: python

df.iloc[[1,2,4],[0,2]]
df.iloc[[1, 2, 4], [0, 2]]

For slicing rows explicitly:

.. ipython:: python

df.iloc[1:3,:]
df.iloc[1:3, :]

For slicing columns explicitly:

.. ipython:: python

df.iloc[:,1:3]
df.iloc[:, 1:3]

For getting a value explicitly:

.. ipython:: python

df.iloc[1,1]
df.iloc[1, 1]

For getting fast access to a scalar (equivalent to the prior method):

.. ipython:: python

df.iat[1,1]
df.iat[1, 1]

Boolean Indexing
~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -303,19 +299,19 @@ Setting values by label:

.. ipython:: python

df.at[dates[0],'A'] = 0
df.at[dates[0], 'A'] = 0

Setting values by position:

.. ipython:: python

df.iat[0,1] = 0
df.iat[0, 1] = 0

Setting by assigning with a NumPy array:

.. ipython:: python

df.loc[:,'D'] = np.array([5] * len(df))
df.loc[:, 'D'] = np.array([5] * len(df))

The result of the prior setting operations.

Expand Down Expand Up @@ -345,7 +341,7 @@ returns a copy of the data.
.. ipython:: python

df1 = df.reindex(index=dates[0:4], columns=list(df.columns) + ['E'])
df1.loc[dates[0]:dates[1],'E'] = 1
df1.loc[dates[0]:dates[1], 'E'] = 1
df1

To drop any rows that have missing data.
Expand Down Expand Up @@ -653,7 +649,8 @@ pandas can include categorical data in a ``DataFrame``. For full docs, see the

.. ipython:: python

df = pd.DataFrame({"id":[1, 2, 3, 4, 5, 6], "raw_grade":['a', 'b', 'b', 'a', 'a', 'e']})
df = pd.DataFrame({"id": [1, 2, 3, 4, 5, 6],
"raw_grade": ['a', 'b', 'b', 'a', 'a', 'e']})

Convert the raw grades to a categorical data type.

Expand All @@ -674,7 +671,8 @@ Reorder the categories and simultaneously add the missing categories (methods un

.. ipython:: python

df["grade"] = df["grade"].cat.set_categories(["very bad", "bad", "medium", "good", "very good"])
df["grade"] = df["grade"].cat.set_categories(["very bad", "bad", "medium",
"good", "very good"])
df["grade"]

Sorting is per order in the categories, not lexical order.
Expand Down Expand Up @@ -703,7 +701,8 @@ See the :ref:`Plotting <visualization>` docs.

.. ipython:: python

ts = pd.Series(np.random.randn(1000), index=pd.date_range('1/1/2000', periods=1000))
ts = pd.Series(np.random.randn(1000),
index=pd.date_range('1/1/2000', periods=1000))
ts = ts.cumsum()

@savefig series_plot_basic.png
Expand Down