How high is inflation? And is it the same in every country?

The latest Bamboo Weekly poses six inflation-related questions to solve with #Python #Pandas, using the latest OECD data.

Read it at: https://BambooWeekly.com

Retrieve selected items from a #Python #Pandas series by broadcasting a condition, then using it as a boolean ("mask") index:

s = pd.Series([10, 20, 30], index=list('abc'))
s >= 20 # [False, True, True]
s.loc[ s >= 20 ] # returns [20, 30]

Retrieve from a #Python #Pandas series with .loc and indexes:

s = pd.Series([10, 20, 30], index=list('abc'))
s.loc[['a', 'c']] # [10, 30]

If you pass booleans, True means "return a value," and False means "ignore it."

s.loc[[True, False, True]] # [10, 30]

Everland's famous twin pandas become Korea's newest travel guides

Korea’s obsession with its resident giant pandas is moving out of the bamboo enclosures and onto the open road. Everland, the country’s largest the...

The Korea Times

Apply an operator to a #Python #Pandas series, with a scalar value, *broadcasts*:

s = pd.Series([10, 20, 30], index=list('abc'))

Arithmetic is most obvious:

s + 5 # [15, 25, 35]
s ** 2 # [100, 400, 900]

But comparisons work, too:

s >= 20 # [False, True, True]

Fixed tests for #Pandas 3.0.3 (latest) in #Guix!

https://codeberg.org/guix/guix/commit/7698140eaca32e5627e70404265acf682f4b6333

This magic trick is taken from upstream but cast a lispy spell

...
(invoke "python" "-c" (format #f "~a; ~a=[~{'~a', ~}]);" "import pandas as pd" "pd.test(extra_args" test-flags))))))))

#guixpythonteam #guixscienceteam

gnu: python-pandas: Update to 3.0.3. · 7698140eac

* gnu/packages/python-science.scm (python-pandas): Update to 3.0.3. [source] <patches>: Drop all. [arguments] <test-flags>: Run more tests and provide extra options. <phases>: Fix custom 'check phase. [propagated-inputs]: Remove python-pytz and python-tzdata; add python-bottleneck, python-lxml, ...

Codeberg.org

What's the fastest way to retrieve the first 2 items from a #Python #Pandas series?

s = pd.Series([10, 20, 30], index=list('abc'))

s.loc[['a','b']] # 108 µs
s.loc['a':'b'] # 22.7 µs
s.iloc[[0, 1]] # 26.7 µs
s.iloc[:2] # 18 µs
s.head(2) # 22.3 µs

Using .loc to retrieve from a #Python #Pandas series is more convenient. But .iloc is faster:

s = pd.Series([10, 20, 30], index=list('abc'))

%timeit s.loc['a'] # 2.09 μs
%timeit s.iloc[0] # 1.5 μs

%timeit s.loc[['a', 'b']] # 105 μs
%timeit s.iloc[[0, 1]] # 26.4 μs

Retrieve from a #Python #Pandas series by position, rather than the index, with iloc:

s = pd.Series([10, 20, 30], index=list('abc'))

s.loc['a'] # 10
s.loc[['a', 'b']] # series of a:10, b:20

s.iloc[0] # 10
s.iloc[[0, 1]] # series of a:10, b:20

Pass a list to .loc on a #Python #Pandas series, and get a series back:

s = pd.Series([10, 20, 30], index=list('abc'))

s.loc[['a']] # series, a:10
s.loc[['a', 'b']] # series, a:10, b:20
s.loc[['a', 'a']] # series, a:10 twice!
s.loc[['b', 'a']] # series, b:20, a:10