Skip to content

Instantly share code, notes, and snippets.

@rohansb
Last active March 29, 2017 21:45
Show Gist options
  • Save rohansb/e462ca5ab010f6aa6d5fe2a00c4f080d to your computer and use it in GitHub Desktop.
Save rohansb/e462ca5ab010f6aa6d5fe2a00c4f080d to your computer and use it in GitHub Desktop.
>>> import numpy as np
>>> weather_yesterday = pd.DataFrame(np.random.randn(10, 5))
>>>
>>> weather_yesterday
0 1 2 3 4
0 -1.022778 -1.146957 -0.455922 3.330690 1.457040
1 -1.694324 0.830800 -0.440014 2.544319 -1.742110
2 -0.434218 0.432943 -1.952516 0.695923 0.830594
3 0.139740 0.170379 0.417473 -0.552355 -1.183856
4 -0.257754 1.197875 0.312274 0.806411 1.171922
5 0.313627 0.316828 -0.245851 0.278327 1.843323
6 -1.792920 -1.228641 -0.125744 -1.642766 -0.960869
7 1.133569 0.148449 -1.363961 -0.233685 0.098531
8 0.314390 0.718867 0.255522 0.019179 0.414491
9 0.463773 -1.630243 -0.675964 -0.049281 1.231596
>>>
>>> weather_yesterday[0]
0 -1.022778
1 -1.694324
2 -0.434218
3 0.139740
4 -0.257754
5 0.313627
6 -1.792920
7 1.133569
8 0.314390
9 0.463773
Name: 0, dtype: float64
>>>
>>> weather_yesterday[0].item()
>>>
>>> weather_yesterday[0].item()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/rbakare/.virtualenvs/gyro/lib/python3.5/site-packages/pandas/core/base.py", line 831, in item
return self.values.item()
ValueError: can only convert an array of size 1 to a Python scalar
>>>
>>> weather_yesterday[0][0].item()
-1.022778257844836
>>>
>>>
>>> bool(0)
False
>>> bool(-1)
True
>>> bool(1)
True
>>>
>>> weather_yesterday[0].any()
True
>>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment