Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 重新采样不起作用_Python_Csv_Pandas - Fatal编程技术网

Python 重新采样不起作用

Python 重新采样不起作用,python,csv,pandas,Python,Csv,Pandas,我读了一本书 pandas.read_csv('/path/me/this.csv', index_col = 'Date', parse_dates = True) 我可以正常地把日期切成薄片。其余列采用正确的数字格式 但是当我尝试用lambda重新取样时 Data.Close.resample('W',how=lambda y:y[-1])我得到一个: IndexError: index out of bounds. 按“总和”正常工作方式重新采样 为什么这不起作用?还有别的办法吗?我想

我读了一本书

pandas.read_csv('/path/me/this.csv', index_col = 'Date', parse_dates = True)
我可以正常地把日期切成薄片。其余列采用正确的数字格式

但是当我尝试用lambda重新取样时

Data.Close.resample('W',how=lambda y:y[-1])
我得到一个:

IndexError: index out of bounds.
按“总和”正常工作方式重新采样

为什么这不起作用?还有别的办法吗?我想按季度或每周对数据进行重新采样,并从周期开始时获得差异。结束/开始-1。
谢谢。

看起来您正在尝试访问最后一个元素,您可以使用
how='last'

Data.Close.resample('W', how ='last')

你能提供一个有问题的示例数据帧吗?你认为这个lambda在重采样的环境下会做什么?谢谢,就是这样。我只是想访问重新采样范围中的最后一个值,我还使用how='first'以相同的方式访问第一个值。