-
-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
DOC: create shared includes for comparison docs #38771
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
:orphan: | ||
|
||
DataFrames can be filtered in multiple ways; the most intuitive of which is using | ||
:ref:`boolean indexing <indexing.boolean>` | ||
|
||
.. ipython:: python | ||
:suppress: | ||
|
||
# ensure tips is defined when scanning with flake8-rst | ||
if 'tips' not in vars(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think you can just add this
but maybe @jorisvandenbossche has a better soln There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But we would want to avoid to read this data multiple times in each file during the doc build, I think, so ideally we can let flake-rst ignore this in a different way There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
sure, any idea how? |
||
tips = {} | ||
|
||
.. ipython:: python | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think in all of these you need a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. It's a bit of a hack, so let me know if you'd like it done differently. |
||
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] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
:orphan: | ||
|
||
The same operation in pandas can be accomplished using | ||
the ``where`` method from ``numpy``. | ||
|
||
.. ipython:: python | ||
:suppress: | ||
|
||
# ensure tips is defined when scanning with flake8-rst | ||
if 'tips' not in vars(): | ||
tips = {} | ||
|
||
.. ipython:: python | ||
|
||
tips["bucket"] = np.where(tips["total_bill"] < 10, "low", "high") | ||
tips.head() | ||
|
||
.. ipython:: python | ||
:suppress: | ||
|
||
tips = tips.drop("bucket", axis=1) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
:orphan: | ||
|
||
pandas objects have a :meth:`DataFrame.sort_values` method, which | ||
takes a list of columns to sort by. | ||
|
||
.. ipython:: python | ||
:suppress: | ||
|
||
# ensure tips is defined when scanning with flake8-rst | ||
if 'tips' not in vars(): | ||
tips = {} | ||
|
||
.. ipython:: python | ||
|
||
tips = tips.sort_values(["sex", "total_bill"]) | ||
tips.head() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
:orphan: | ||
|
||
.. ipython:: python | ||
:suppress: | ||
|
||
# ensure tips is defined when scanning with flake8-rst | ||
if 'tips' not in vars(): | ||
tips = {} | ||
|
||
.. 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, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the only change of substance: left out the
LIMIT
and the.head(5)
below since they aren't needed andLIMIT
is covered elsewhere.