Skip to content

Instantly share code, notes, and snippets.

@nickhs
Created February 10, 2016 18:41
Show Gist options
  • Save nickhs/5df2a8783a5a67e220f0 to your computer and use it in GitHub Desktop.
Save nickhs/5df2a8783a5a67e220f0 to your computer and use it in GitHub Desktop.
In [1]: %matplotlib qt
In [2]: import numpy as np
In [3]: import pandas
In [4]: x = np.random.rand(1, 100) * 100
In [5]: x
Out[5]:
array([[ 31.52994306, 27.0837805 , 33.90521734, 7.81624911,
94.16987949, 28.39108981, 53.55282751, 2.76310603,
88.06353126, 32.23307981, 63.00215162, 27.10032206,
37.15109043, 91.68872297, 55.03006991, 43.61004024,
29.94035752, 69.1287253 , 94.99335713, 40.29024672,
77.18706521, 26.64955824, 79.13713719, 88.67493152,
1.68759453, 48.15853548, 99.05450679, 74.4452181 ,
17.00973416, 66.050491 , 56.79314643, 51.68895139,
20.20797535, 11.75945424, 84.24547559, 32.00888191,
92.29912045, 24.22421894, 20.37503263, 65.54743954,
44.07153752, 65.6113049 , 78.47281165, 44.87353296,
84.62428066, 10.96547979, 59.13830519, 42.10934064,
8.46759015, 37.63909805, 60.70344327, 67.49294925,
12.11031029, 13.85780179, 71.03470453, 6.18474855,
66.38387979, 19.76043282, 45.08657856, 28.62964671,
39.8930534 , 65.76321125, 73.85521824, 94.89151588,
37.56637575, 37.15314425, 64.33288323, 10.96763029,
79.89277552, 6.25780789, 92.81232913, 95.26988272,
91.2067481 , 56.44313349, 11.11227766, 42.82539788,
98.91529372, 44.09645277, 89.60637178, 64.70873332,
2.39855946, 68.18908929, 86.05233306, 10.37694636,
49.02441349, 29.1022 , 57.50062669, 23.53124511,
66.33491069, 50.9733553 , 66.74909567, 26.04383624,
16.02023859, 79.16229866, 89.42715443, 33.68157573,
85.54034076, 14.36538464, 10.13151483, 96.13846944]])
In [6]: df = pandas.DataFrame(x)
In [7]: df
Out[7]:
0 1 2 3 4 5 6 \
0 31.529943 27.083781 33.905217 7.816249 94.169879 28.39109 53.552828
7 8 9 ... 90 91 92 \
0 2.763106 88.063531 32.23308 ... 66.749096 26.043836 16.020239
93 94 95 96 97 98 99
0 79.162299 89.427154 33.681576 85.540341 14.365385 10.131515 96.138469
[1 rows x 100 columns]
In [8]: df.plot()
/usr/local/python/python-2.7/std/lib/python2.7/site-packages/matplotlib/axes/_base.py:2767: UserWarning: Attempting to set identical left==right results
in singular transformations; automatically expanding.
left=0.0, right=0.0
'left=%s, right=%s') % (left, right))
Out[8]: <matplotlib.axes._subplots.AxesSubplot at 0x7f2e9bc746d0>
In [9]: df
Out[9]:
0 1 2 3 4 5 6 \
0 31.529943 27.083781 33.905217 7.816249 94.169879 28.39109 53.552828
7 8 9 ... 90 91 92 \
0 2.763106 88.063531 32.23308 ... 66.749096 26.043836 16.020239
93 94 95 96 97 98 99
0 79.162299 89.427154 33.681576 85.540341 14.365385 10.131515 96.138469
[1 rows x 100 columns]
In [10]: df.cols()
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-10-6dbd35a0d9bf> in <module>()
----> 1 df.cols()
/usr/local/python/python-2.7/std/lib/python2.7/site-packages/pandas/core/generic.py in __getattr__(self, name)
2358 return self[name]
2359 raise AttributeError("'%s' object has no attribute '%s'" %
-> 2360 (type(self).__name__, name))
2361
2362 def __setattr__(self, name, value):
AttributeError: 'DataFrame' object has no attribute 'cols'
In [11]: df.T
Out[11]:
0
0 31.529943
1 27.083781
2 33.905217
3 7.816249
4 94.169879
5 28.391090
6 53.552828
7 2.763106
8 88.063531
9 32.233080
10 63.002152
11 27.100322
12 37.151090
13 91.688723
14 55.030070
15 43.610040
16 29.940358
17 69.128725
18 94.993357
19 40.290247
20 77.187065
21 26.649558
22 79.137137
23 88.674932
24 1.687595
25 48.158535
26 99.054507
27 74.445218
28 17.009734
29 66.050491
.. ...
70 92.812329
71 95.269883
72 91.206748
73 56.443133
74 11.112278
75 42.825398
76 98.915294
77 44.096453
78 89.606372
79 64.708733
80 2.398559
81 68.189089
82 86.052333
83 10.376946
84 49.024413
85 29.102200
86 57.500627
87 23.531245
88 66.334911
89 50.973355
90 66.749096
91 26.043836
92 16.020239
93 79.162299
94 89.427154
95 33.681576
96 85.540341
97 14.365385
98 10.131515
99 96.138469
[100 rows x 1 columns]
In [12]: df.T.plot()
Out[12]: <matplotlib.axes._subplots.AxesSubplot at 0x7f2e8ee3d790>
In [13]: df.T.plot(kind="bar")
Out[13]: <matplotlib.axes._subplots.AxesSubplot at 0x7f2e8ed50b10>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment