小编min*_*hau的帖子

如何理解pandas resample方法中的闭包和标签参数?

基于此处的pandas文档:Docs

和例子:

>>> index = pd.date_range('1/1/2000', periods=9, freq='T')
>>> series = pd.Series(range(9), index=index)
>>> series
2000-01-01 00:00:00    0
2000-01-01 00:01:00    1
2000-01-01 00:02:00    2
2000-01-01 00:03:00    3
2000-01-01 00:04:00    4
2000-01-01 00:05:00    5
2000-01-01 00:06:00    6
2000-01-01 00:07:00    7
2000-01-01 00:08:00    8
Freq: T, dtype: int64
Run Code Online (Sandbox Code Playgroud)

重新取样后:

>>> series.resample('3T', label='right', closed='right').sum()
2000-01-01 00:00:00     0
2000-01-01 00:03:00     6
2000-01-01 00:06:00    15
2000-01-01 00:09:00    15
Run Code Online (Sandbox Code Playgroud)

在我的想法中,重新取样后的垃圾箱看起来应该是这样的:

=========bin 01=========
2000-01-01 00:00:00    0
2000-01-01 00:01:00    1
2000-01-01 00:02:00    2

=========bin 02=========
2000-01-01 00:03:00 …
Run Code Online (Sandbox Code Playgroud)

python time-series dataframe pandas

5
推荐指数
2
解决办法
1968
查看次数

为什么回溯打印早于打印 url?

据我所知,当运行以下代码时,print(url, end='')将首先打印一行。

然后requests.get(url)引发异常,从而触发traceback.print_exc().

但在我的测试中,traceback.print_exc()屏幕上的打印早于print(url, end='').

为什么?

另一方面,如果我用 替换traceback.print_exc()print('error occurred')它就会按照我的想法工作。

看来 的traceback.print_exc()优先级更高?

import traceback

import requests


url = 'http://www.szwb.gov.cn/wap/jggk/gzdt/201809/t20180919_14099889.htm'

try:
    print(url, end='')
    response = requests.get(url)
    # balabala
except Exception as e:
    traceback.print_exc()
    # print('error occurred.')
Run Code Online (Sandbox Code Playgroud)

python traceback

3
推荐指数
1
解决办法
576
查看次数

pycharm正则表达式替换字符串并保留原​​始匹配的字符串

在 .py 文件中,有许多串联的 sql 查询。其中包含

and a.created_at >='2019-01-01'
...
and b.deleted_at >='2019-01-01'
...
and c.received_at >='2019-01-01'
Run Code Online (Sandbox Code Playgroud)

现在我想注释掉这些时间比较代码,让它们可以使用

-- and a.created_at >='2019-01-01'
...
-- and b.deleted_at >='2019-01-01'
...
-- and c.received_at >='2019-01-01'
Run Code Online (Sandbox Code Playgroud)

我可以用来and (.*?) >='2019-01-01'匹配这些比较。

如何添加--替代品?

regex pycharm

1
推荐指数
1
解决办法
421
查看次数

标签 统计

python ×2

dataframe ×1

pandas ×1

pycharm ×1

regex ×1

time-series ×1

traceback ×1