import numpy as np
import pandas as pd
mydates = pd.date_range('1/1/2012', periods=1000, freq='D')
myts = pd.Series(np.random.randn(len(mydates)), index=mydates)
grouped = myts.groupby(lambda x: x.timetuple()[7])
mymin = grouped.min()
mymax = grouped.max()
以上给了我想要的东西,在一年中的朱利安日汇总统计数据但是我想重新排序该组,以便将上半场(183天)放在上半场前面.
使用普通的numpy数组:
myindex = np.arange(1,367)
myindex = np.concatenate((myindex[183:],myindex[:183]))
但我不能用groupby这样做会引发一个not implement错误.
注意:这是google-groups的交叉帖子.另外我一直在读comp.lang.python,不幸的是人们往往会忽略一些帖子,例如来自谷歌团体.
提前致谢,
贝文
解决方法:
为什么不重新索引结果?
In [7]: mymin.reindex(myindex)
Out[7]:
184 -0.788140
185 -2.206314
186 0.284884
187 -2.197727
188 -0.714634
189 -1.082745
190 -0.789286
191 -1.489837
192 -1.278941
193 -0.795507
194 -0.661476
195 0.582994
196 -1.634310
197 0.104332
198 -0.602378
...
169 -1.150616
170 -0.315325
171 -2.233139
172 -1.081528
173 -1.316668
174 -0.963783
175 -0.215260
176 -2.723446
177 -0.493480
178 -0.706771
179 -2.082051
180 -1.066649
181 -1.455419
182 -0.332383
183 -1.277424
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。