python - 查找元素更改值 Pandas 数据框的索引

标签 python pandas

关于this question/answer , 有没有办法在不将其转换为 numpy 数组的情况下为 Pandas 数据帧结构完成相同的功能?

最佳答案

更新:我们可以根据@LorenzoMeneghetti 使用它

s[s.diff() != 0].index.tolist()
输出:
[0, 5, 8, 9, 10, 11, 12, 13, 14, 15, 16]
s = pd.Series([1, 1, 1, 1, 1, 2, 2, 2, 3, 4, 3, 4, 3, 4, 3, 4, 5, 5, 5])

print(s.diff()[s.diff() != 0].index.values)
或者:
df = pd.DataFrame([1, 1, 1, 1, 1, 2, 2, 2, 3, 4, 3, 4, 3, 4, 3, 4, 5, 5, 5])

print(df[0].diff()[df[0].diff() != 0].index.values)
输出:
[ 0 5 8 9 10 11 12 13 14 15 16]

关于python - 查找元素更改值 Pandas 数据框的索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43524953/

相关文章:

python - 将 numpy n 维数组转换为 pandas n 维数据帧(可扩展)

python - 如何对多列进行分组并计算pandas中的百分比

python - addStretch 在 QBoxLayout 中究竟是如何工作的?

python - 在 Python Pandas read_csv 中使用多字符定界符

python - 如何制作一个为输入表的每一行计算结果的python程序?

python:退出两个循环

python - 用表格打印多索引数据框

python - 如何将行追加到 Gtk.ListStore?

python - MYSQL CONNECTOR加载数据本地文件: file could not be read

python - 加速在给定范围内查找倍数的算法