pycse.utils#

These are some convenience utilities.

Float comparisons#

Floating point math is hard.

0.3 == 0.1 + 0.2
False

pycse.utils provides several floating point comparison operators:

  • feq a == b

  • flt a < b

  • fgt a > b

  • fle a <= b

  • fge a >= b

from pycse.utils import feq

feq(0.3, 0.1 + 0.2)
True

Temporarily ignore errors#

This context manager wraps code in a try/except/finally clause so you can ignore some errors.

1 / 0
---------------------------------------------------------------------------
ZeroDivisionError                         Traceback (most recent call last)
Cell In[3], line 1
----> 1 1 / 0

ZeroDivisionError: division by zero
from pycse.utils import ignore_exception
with ignore_exception(ZeroDivisionError):
    1 / 0
caught division by zero
done

Read a Google Sheet into a pandas Dataframe#

You can use a url to a Google Sheet that is publicly visible to read it into a pandas Dataframe.

from pycse.utils import read_gsheet
read_gsheet('https://docs.google.com/spreadsheets/d/1Qh4H5lHw_HOScAZqvII1VRPwCpPEJTHwkbo3a323azg/')
x y
0 1 2
1 2 4
2 3 6