Skip to content

Commit 4c54aaa

Browse files
authored
Improve code style in tutorial (#293)
Prefer square bracket access for columns since dotted access is only for convenience. Shorten long lines for readability.
1 parent fafd627 commit 4c54aaa

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

docs/getting/tutorial.rst

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,9 @@ Next, we create a DataFrame with PintArrays as columns.
2626

2727
.. ipython:: python
2828
29-
df = pd.DataFrame(
30-
{
31-
"torque": pd.Series([1.0, 2.0, 2.0, 3.0], dtype="pint[lbf ft]"),
32-
"angular_velocity": pd.Series([1.0, 2.0, 2.0, 3.0], dtype="pint[rpm]"),
33-
}
34-
)
29+
df = pd.DataFrame({
30+
"torque": pd.Series([1, 2, 2, 3], dtype="pint[lbf ft]")
31+
"angular_velocity": pd.Series([1, 2, 2, 3], dtype="pint[rpm]")})
3532
df
3633
3734
@@ -61,19 +58,19 @@ Each column can be accessed as a Pandas Series
6158

6259
.. ipython:: python
6360
64-
df.power
61+
df["power"]
6562
6663
Which contains a PintArray
6764

6865
.. ipython:: python
6966
70-
df.power.values
67+
df["power"].values
7168
7269
The PintArray contains a Quantity
7370

7471
.. ipython:: python
7572
76-
df.power.values.quantity
73+
df["power"].values.quantity
7774
7875
DataFrame Index
7976
-----------------------
@@ -93,8 +90,8 @@ Methods that return arrays will be converted to Series.
9390

9491
.. ipython:: python
9592
96-
df.power.pint.units
97-
df.power.pint.to("kW")
93+
df["power"].pint.units
94+
df["power"].pint.to("kW")
9895
9996
10097
That's the basics! More examples are given at :doc:`Reading from csv <../user/reading>`.

0 commit comments

Comments
 (0)