Skip to content

DOC: Fix dsintro.rst flake8 issues #24187

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
Dec 10, 2018
Merged
Show file tree
Hide file tree
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
61 changes: 30 additions & 31 deletions doc/source/dsintro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Series can be instantiated from dicts:

.. ipython:: python

d = {'b' : 1, 'a' : 0, 'c' : 2}
d = {'b': 1, 'a': 0, 'c': 2}
pd.Series(d)

.. note::
Expand All @@ -92,7 +92,7 @@ index will be pulled out.

.. ipython:: python

d = {'a' : 0., 'b' : 1., 'c' : 2.}
d = {'a': 0., 'b': 1., 'c': 2.}
pd.Series(d)
pd.Series(d, index=['b', 'c', 'd', 'a'])

Expand Down Expand Up @@ -304,8 +304,8 @@ keys.

.. ipython:: python

d = {'one' : pd.Series([1., 2., 3.], index=['a', 'b', 'c']),
'two' : pd.Series([1., 2., 3., 4.], index=['a', 'b', 'c', 'd'])}
d = {'one': pd.Series([1., 2., 3.], index=['a', 'b', 'c']),
'two': pd.Series([1., 2., 3., 4.], index=['a', 'b', 'c', 'd'])}
df = pd.DataFrame(d)
df

Expand Down Expand Up @@ -334,8 +334,8 @@ result will be ``range(n)``, where ``n`` is the array length.

.. ipython:: python

d = {'one' : [1., 2., 3., 4.],
'two' : [4., 3., 2., 1.]}
d = {'one': [1., 2., 3., 4.],
'two': [4., 3., 2., 1.]}
pd.DataFrame(d)
pd.DataFrame(d, index=['a', 'b', 'c', 'd'])

Expand All @@ -346,8 +346,8 @@ This case is handled identically to a dict of arrays.

.. ipython:: python

data = np.zeros((2,), dtype=[('A', 'i4'),('B', 'f4'),('C', 'a10')])
data[:] = [(1,2.,'Hello'), (2,3.,"World")]
data = np.zeros((2, ), dtype=[('A', 'i4'), ('B', 'f4'), ('C', 'a10')])
data[:] = [(1, 2., 'Hello'), (2, 3., "World")]

pd.DataFrame(data)
pd.DataFrame(data, index=['first', 'second'])
Expand Down Expand Up @@ -507,17 +507,15 @@ derived from existing columns.

iris = pd.read_csv('data/iris.data')
iris.head()

(iris.assign(sepal_ratio = iris['SepalWidth'] / iris['SepalLength'])
(iris.assign(sepal_ratio=iris['SepalWidth'] / iris['SepalLength'])
.head())

In the example above, we inserted a precomputed value. We can also pass in
a function of one argument to be evaluated on the DataFrame being assigned to.

.. ipython:: python

iris.assign(sepal_ratio = lambda x: (x['SepalWidth'] /
x['SepalLength'])).head()
iris.assign(sepal_ratio=lambda x: (x['SepalWidth'] / x['SepalLength'])).head()

``assign`` **always** returns a copy of the data, leaving the original
DataFrame untouched.
Expand All @@ -532,8 +530,8 @@ greater than 5, calculate the ratio, and plot:

@savefig basics_assign.png
(iris.query('SepalLength > 5')
.assign(SepalRatio = lambda x: x.SepalWidth / x.SepalLength,
PetalRatio = lambda x: x.PetalWidth / x.PetalLength)
.assign(SepalRatio=lambda x: x.SepalWidth / x.SepalLength,
PetalRatio=lambda x: x.PetalWidth / x.PetalLength)
.plot(kind='scatter', x='SepalRatio', y='PetalRatio'))

Since a function is passed in, the function is computed on the DataFrame
Expand Down Expand Up @@ -705,8 +703,8 @@ Boolean operators work as well:

.. ipython:: python

df1 = pd.DataFrame({'a' : [1, 0, 1], 'b' : [0, 1, 1] }, dtype=bool)
df2 = pd.DataFrame({'a' : [0, 1, 1], 'b' : [1, 1, 0] }, dtype=bool)
df1 = pd.DataFrame({'a': [1, 0, 1], 'b': [0, 1, 1]}, dtype=bool)
df2 = pd.DataFrame({'a': [0, 1, 1], 'b': [1, 1, 0]}, dtype=bool)
df1 & df2
df1 | df2
df1 ^ df2
Expand Down Expand Up @@ -746,7 +744,7 @@ Similarly, the dot method on Series implements dot product:

.. ipython:: python

s1 = pd.Series(np.arange(5,10))
s1 = pd.Series(np.arange(5, 10))
s1.dot(s1)

DataFrame is not intended to be a drop-in replacement for ndarray as its
Expand Down Expand Up @@ -777,7 +775,7 @@ R package):
:okwarning:

# restore GlobalPrintConfig
pd.reset_option('^display\.')
pd.reset_option('^display\.') # noqa: W605

However, using ``to_string`` will return a string representation of the
DataFrame in tabular form, though it won't always fit the console width:
Expand All @@ -798,22 +796,22 @@ option:

.. ipython:: python

pd.set_option('display.width', 40) # default is 80
pd.set_option('display.width', 40) # default is 80

pd.DataFrame(np.random.randn(3, 12))

You can adjust the max width of the individual columns by setting ``display.max_colwidth``

.. ipython:: python

datafile={'filename': ['filename_01','filename_02'],
'path': ["media/user_name/storage/folder_01/filename_01",
"media/user_name/storage/folder_02/filename_02"]}
datafile = {'filename': ['filename_01', 'filename_02'],
'path': ["media/user_name/storage/folder_01/filename_01",
"media/user_name/storage/folder_02/filename_02"]}

pd.set_option('display.max_colwidth',30)
pd.set_option('display.max_colwidth', 30)
pd.DataFrame(datafile)

pd.set_option('display.max_colwidth',100)
pd.set_option('display.max_colwidth', 100)
pd.DataFrame(datafile)

.. ipython:: python
Expand All @@ -833,8 +831,8 @@ accessed like an attribute:

.. ipython:: python

df = pd.DataFrame({'foo1' : np.random.randn(5),
'foo2' : np.random.randn(5)})
df = pd.DataFrame({'foo1': np.random.randn(5),
'foo2': np.random.randn(5)})
df
df.foo1

Expand All @@ -843,7 +841,7 @@ completion mechanism so they can be tab-completed:

.. code-block:: ipython

In [5]: df.fo<TAB>
In [5]: df.fo<TAB> # noqa: E225, E999
df.foo1 df.foo2

.. _basics.panel:
Expand Down Expand Up @@ -890,8 +888,8 @@ From dict of DataFrame objects
.. ipython:: python
:okwarning:

data = {'Item1' : pd.DataFrame(np.random.randn(4, 3)),
'Item2' : pd.DataFrame(np.random.randn(4, 2))}
data = {'Item1': pd.DataFrame(np.random.randn(4, 3)),
'Item2': pd.DataFrame(np.random.randn(4, 2))}
pd.Panel(data)

Note that the values in the dict need only be **convertible to
Expand Down Expand Up @@ -947,8 +945,9 @@ From DataFrame using ``to_panel`` method
.. ipython:: python
:okwarning:

midx = pd.MultiIndex(levels=[['one', 'two'], ['x','y']], codes=[[1,1,0,0],[1,0,1,0]])
df = pd.DataFrame({'A' : [1, 2, 3, 4], 'B': [5, 6, 7, 8]}, index=midx)
midx = pd.MultiIndex(levels=[['one', 'two'], ['x', 'y']],
codes=[[1, 1, 0, 0], [1, 0, 1, 0]])
df = pd.DataFrame({'A': [1, 2, 3, 4], 'B': [5, 6, 7, 8]}, index=midx)
df.to_panel()

.. _dsintro.panel_item_selection:
Expand Down
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ exclude =
doc/source/10min.rst
doc/source/basics.rst
doc/source/contributing_docstring.rst
doc/source/dsintro.rst
doc/source/enhancingperf.rst
doc/source/groupby.rst
doc/source/indexing.rst
Expand Down