-
-
Notifications
You must be signed in to change notification settings - Fork 17.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DOC: create shared includes for content shared by comparison docs
This will help ensure consistency between the examples.
- Loading branch information
Showing
10 changed files
with
94 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
doc/source/getting_started/comparison/includes/construct_dataframe.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
:orphan: | ||
|
||
A pandas ``DataFrame`` can be constructed in many different ways, | ||
but for a small number of values, it is often convenient to specify it as | ||
a Python dictionary, where the keys are the column names | ||
and the values are the data. | ||
|
||
.. ipython:: python | ||
df = pd.DataFrame({"x": [1, 3, 5], "y": [2, 4, 6]}) | ||
df |
18 changes: 18 additions & 0 deletions
18
doc/source/getting_started/comparison/includes/filtering.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
:orphan: | ||
|
||
DataFrames can be filtered in multiple ways; the most intuitive of which is using | ||
:ref:`boolean indexing <indexing.boolean>` | ||
|
||
.. ipython:: python | ||
tips[tips["total_bill"] > 10] | ||
The above statement is simply passing a ``Series`` of ``True``/``False`` objects to the DataFrame, | ||
returning all rows with ``True``. | ||
|
||
.. ipython:: python | ||
is_dinner = tips["time"] == "Dinner" | ||
is_dinner | ||
is_dinner.value_counts() | ||
tips[is_dinner] |
14 changes: 14 additions & 0 deletions
14
doc/source/getting_started/comparison/includes/if_then.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
:orphan: | ||
|
||
The same operation in pandas can be accomplished using | ||
the ``where`` method from ``numpy``. | ||
|
||
.. ipython:: python | ||
tips["bucket"] = np.where(tips["total_bill"] < 10, "low", "high") | ||
tips.head() | ||
.. ipython:: python | ||
:suppress: | ||
tips = tips.drop("bucket", axis=1) |
2 changes: 2 additions & 0 deletions
2
...ted/comparison/comparison_boilerplate.rst → ...rted/comparison/includes/introduction.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
:orphan: | ||
|
||
pandas objects have a :meth:`DataFrame.sort_values` method, which | ||
takes a list of columns to sort by. | ||
|
||
.. ipython:: python | ||
tips = tips.sort_values(["sex", "total_bill"]) | ||
tips.head() |
24 changes: 24 additions & 0 deletions
24
doc/source/getting_started/comparison/includes/time_date.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
:orphan: | ||
|
||
.. ipython:: python | ||
tips["date1"] = pd.Timestamp("2013-01-15") | ||
tips["date2"] = pd.Timestamp("2015-02-15") | ||
tips["date1_year"] = tips["date1"].dt.year | ||
tips["date2_month"] = tips["date2"].dt.month | ||
tips["date1_next"] = tips["date1"] + pd.offsets.MonthBegin() | ||
tips["months_between"] = tips["date2"].dt.to_period("M") - tips[ | ||
"date1" | ||
].dt.to_period("M") | ||
tips[ | ||
["date1", "date2", "date1_year", "date2_month", "date1_next", "months_between"] | ||
].head() | ||
.. ipython:: python | ||
:suppress: | ||
tips = tips.drop( | ||
["date1", "date2", "date1_year", "date2_month", "date1_next", "months_between"], | ||
axis=1, | ||
) |