python - 切片索引 Dask 数据帧
问题描述
有没有一种简单的方法来切片 Dask 数据帧索引:
Pandas 中有类似的东西吗?
index_element = df.index[-1]
解决方案
你追求什么?
在dask数据帧上做.index[i]
将给出
import dask.dataframe as dd
df = dd.demo.make_timeseries(
start="2000-01-01",
end="2000-01-03",
dtypes={"id": int, "z": int},
freq="1h",
partition_freq="24h",
)
df.index[-1]
---------------------------------------------------------------------------
NotImplementedError Traceback (most recent call last)
<ipython-input-7-d70d3c1197c1> in <module>
----> 1 df.index[-1]
~/miniconda/envs/main/lib/python3.8/site-packages/dask/dataframe/core.py in __getitem__(self, key)
3172 graph = HighLevelGraph.from_collections(name, dsk, dependencies=[self, key])
3173 return Series(graph, name, self._meta, self.divisions)
-> 3174 raise NotImplementedError(
3175 "Series getitem in only supported for other series objects "
3176 "with matching partition structure"
NotImplementedError: Series getitem in only supported for other series objects with matching partition structure
如果您在最后一行的索引之后,您可以这样做:
df.tail(1).index
给
DatetimeIndex(['2000-01-02 23:00:00'], dtype='datetime64[ns]', name='timestamp', freq='H')
推荐阅读
- google-app-maker - AppMaker - 导航到表格的最后一页
- java - JDBI 间隔 postgresql
- c# - 如何在 StoryBoard MediaTimeLine 中显示持续时间 x 的图像并在第一个图像持续时间完成后播放另一个视频或图像?
- bash - 运行 bash vs dash 时与 $((++n)) 的结果不同
- python - 为什么 CPU 上的 Keras LSTM 比 GPU 快三倍?
- android - 无法在 Android 上加载 svg 资源
- java - Gson 反序列化抛出 FutureTask 错误
- arrays - 从MongoDB中的数组中查找最小值和最大值
- hive - Hive 查询 - “MINUS”
- php - PHP - 如何知道从哪里调用魔术方法 __call()