python - pandas:索引值数组中的系列值

标签 python pandas series

我有一个 pandas Series 实例,定义如下:

import pandas as pd
timestamps = [1,2,3,4,5,6,7,8,9,10]
quantities = [1,9,6,6,6,4,4,4,5,2]
series = pd.Series(quantities, index=timestamps)

是否可以提供索引值数组并检索它们的数量?如果是的话,实现这一目标的最快方法是什么?

例如,如果我提供:

timestamps = [1,1,1,4]

我希望系列返回以下内容:

quantities = [1,1,1,6]

感谢您的帮助。

最佳答案

有可能:

>>> series[[1,1,1,4]]
1    1
1    1
1    1
4    6
dtype: int64
>>> series[[1,1,1,4]].values
array([1, 1, 1, 6])

关于python - pandas:索引值数组中的系列值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55505923/

相关文章:

python - 将对象转换为日期时间

python - Nu 是不可行的

python - 有没有办法通过 Python 中的每个第 n 个分隔符来拆分字符串?

python - 如何允许用户在 Django Rest Framework 中仅修改他的数据

python - 取消透视数据框并加入 Pandas

python - 使用 pandas 在 CSV 文件中写入注释

python - 如何使用getattr调用字符串作为属性?

python - PyTorch模型验证: The size of tensor a (32) must match the size of tensor b (13)

python - 多级列上的 Pandas get_dummies()

c# - 在图表winform中更改颜色的问题