Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #53648
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2013-09-04 13:06 -0700 |
| Message-ID | <6b13a66f-ff9a-4f82-b2d1-2231b8f4e94e@googlegroups.com> (permalink) |
| Subject | Broadcasting TimeSeries |
| From | Davide Dalmasso <davide.dalmasso@gmail.com> |
Hello,
I opened my Python Shell and I wrote the following:
>>> import numpy as np
>>> import pandas as pd
then I made a function
>>> def afunc(aframe):
return aframe - aframe.mean(axis=1)
and I defined a DataFrame with time as index
>>> A = pd.DataFrame(np.random.randn(5,3),columns=['a','b','c'],index=pd.date_range(start='1984-12-20',periods=5))
>>> A
a b c
1984-12-20 -0.257916 -0.137923 -0.669796
1984-12-21 -1.632874 -1.850365 1.571715
1984-12-22 1.185828 -0.149839 -1.565930
1984-12-23 -0.757311 0.034627 0.794608
1984-12-24 0.548785 -1.126786 -0.438457
now, if I call the function the following error is generated:
>>> afunc(A)
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
afunc(A)
File "<pyshell#3>", line 2, in afunc
return aframe - aframe.mean(axis=1)
File "C:\Python33\lib\site-packages\pandas\core\frame.py", line 217, in f
return self._combine_series(other, na_op, fill_value, axis, level)
File "C:\Python33\lib\site-packages\pandas\core\frame.py", line 3601, in _combine_series
return self._combine_series_infer(other, func, fill_value)
File "C:\Python33\lib\site-packages\pandas\core\frame.py", line 3619, in _combine_series_infer
FutureWarning)
File "C:\Python33\lib\idlelib\PyShell.py", line 60, in idle_showwarning
file.write(warnings.formatwarning(message, category, filename,
AttributeError: 'NoneType' object has no attribute 'write'
then I recall the same function (without any change) and the function works!
>>> afunc(A)
a b c
1984-12-20 0.097295 0.217289 -0.314584
1984-12-21 -0.995699 -1.213190 2.208890
1984-12-22 1.362475 0.026808 -1.389283
1984-12-23 -0.781285 0.010652 0.770633
1984-12-24 0.887604 -0.787967 -0.099637
Why does this happen? Why I must call the function two times before it finally works?
How can I overcome this problem?
Many thanks in advance
Davide
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Broadcasting TimeSeries Davide Dalmasso <davide.dalmasso@gmail.com> - 2013-09-04 13:06 -0700 Re: Broadcasting TimeSeries Terry Reedy <tjreedy@udel.edu> - 2013-09-04 18:00 -0400
csiph-web