- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我从 pandas 数据框中抓取了一列,并从行中创建了一个列表。如果我打印列表的前两个值,我会得到以下输出:
print dfList[0]
print dfList[1]
0 0.00
1 0.00
2 0.00
3 0.00
4 0.00
5 0.11
6 0.84
7 1.00
8 0.27
9 0.00
10 0.52
11 0.55
12 0.92
13 0.00
14 0.00
...
50 0.42
51 0.00
52 0.00
53 0.00
54 0.40
55 0.65
56 0.81
57 1.00
58 0.54
59 0.21
60 0.00
61 0.33
62 1.00
63 0.75
64 1.00
Name: 9, Length: 65, dtype: float64
65 1.00
66 1.00
67 1.00
68 1.00
69 1.00
70 1.00
71 0.55
72 0.00
73 0.39
74 0.51
75 0.70
76 0.83
77 0.87
78 0.85
79 0.53
...
126 0.83
127 0.83
128 0.83
129 0.71
130 0.26
131 0.11
132 0.00
133 0.00
134 0.50
135 1.00
136 1.00
137 0.59
138 0.59
139 0.59
140 1.00
Name: 9, Length: 76, dtype: float64
当我尝试使用 for 循环迭代列表时,收到一条错误消息:
for i in dfList:
print dfList[i]
Traceback (most recent call last):
File "./windows.py", line 84, in <module>
print dfList[i]
TypeError: list indices must be integers, not Series
如果我将代码编写为:
for i in dfList:
print i
我得到了正确的输出:
0 0.00
1 0.00
2 0.00
3 0.00
4 0.00
5 0.11
6 0.84
7 1.00
8 0.27
9 0.00
10 0.52
11 0.55
12 0.92
13 0.00
14 0.00
...
50 0.42
51 0.00
52 0.00
53 0.00
54 0.40
55 0.65
56 0.81
57 1.00
58 0.54
59 0.21
60 0.00
61 0.33
62 1.00
63 0.75
64 1.00
Name: 9, Length: 65, dtype: float64
...
...
Name: 9, Length: 108, dtype: float64
507919 0.00
507920 0.83
507921 1.00
507922 1.00
507923 0.46
507924 0.83
507925 1.00
507926 1.00
507927 1.00
507928 1.00
507929 1.00
507930 1.00
507931 1.00
507932 1.00
507933 1.00
...
508216 1
508217 1
508218 1
508219 1
508220 1
508221 1
508222 1
508223 1
508224 1
508225 1
508226 1
508227 1
508228 1
508229 1
508230 1
Name: 9, Length: 312, dtype: float64
我不知道为什么会发生这种情况。
我最终想要迭代 5 个连续“窗口”的列表并计算它们的平均值并将这些平均值放入列表中。
最佳答案
在Python中,当您编写for i in
时,i
是元素,而不是您需要的索引,然后打印i
而不是打印 dfList[i]
.
以下两个选项都可以:
for i in dfList[i]:
print i
for i in range(len(dfList)):
print dfList[i]
第一个更加Pythonic和优雅,除非你需要索引。
正如 jwilner 建议的那样,您也可以这样做:
for i, element in enumerate(dfList):
print i, element
这里i
是索引,element
是dfList[i]
。
关于python - 错误 : list indices must be integers, 不是系列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29810920/
我有一个 TableView,每个单元格的附件都设置为“披露指示器”,它工作正常。 然后,我决定在使用外部来源的数据更新每个单元格时添加一个事件指示器。为此,我设置了: cell.accessoryV
我正在尝试遵循来自 here 的公认解决方案在 Xcode 6.3.2 上,但指示器拒绝显示,或者由于某种原因我在 iPhone 6 plus 上看不到它。没有错误消息、带有标题的警告等显示,并且空白
我的 JavaFX 应用程序计算另一个文件夹下一层的每个文件夹的大小。我的问题是,当我点击“应用”按钮(该按钮在另一个类中开始计算)时,我想要一个不确定的进度指示器来向用户显示该应用程序正在运行并且尚
One of the biggest causes of instability in Elasticsearch is fielddata: field values have to be load
我在实验宇宙学中做一些模拟,在使用 numpy 数组时遇到了这个问题。我是 numpy 的新手,所以我不确定我是否做错了或者这是一个错误。我跑: Enthought Python Distributi
我有一个结构数组,这些结构基本上是形成一条边的两个点。由于性能,我使用结构。 现在我有对象 A 保存边缘和这个对象中的一个方法来告诉另一个对象 B 关于这个边缘数组中的连续边缘列表。 边缘: e0 e
我正在使用 Elasticsearch ( Official PHP client) 开发一个 PHP 网站。 我正在编写需要确定新插入文档的测试在继续之前准备好搜索。 为此,在索引新文档后,我调用:
我是 DirectX 12 的新手,正在尝试在 DX 上渲染网格。到目前为止,我成功地从 obj 和 fbx 文件中检索顶点和索引,并使用模板通用窗口项目在 DX 12 上渲染所有顶点。但是,我遇到了
我是 DirectX 12 的新手,正在尝试在 DX 上渲染网格。到目前为止,我成功地从 obj 和 fbx 文件中检索顶点和索引,并使用模板通用窗口项目在 DX 12 上渲染所有顶点。但是,我遇到了
我正在使用 StratifiedKFold 创建用于拆分数据的索引。它给了我索引超出范围的错误。 Xdev的索引从0到47503。 cv_index 变量的 min 和 max 索引分别为 0 和 1
我想绘制以下 UIPageControl 指示器: 我目前有以下代码,结果是: if (isHighlighted) { UIBezierPath *ovalPath = [UIBezierP
我们在以下用例中使用 elasticsearch。 Elasticsearch 版本:5.1.1 注意:我们使用的是 AWS 托管的 ElasticSearch 我们有一个 Multi-Tenancy
我正在尝试使用 scikit-learn 中的算法根据大量输入来预测输出。我似乎收到错误“索引过多”,但无法弄清楚原因。 CSV 文件训练: 1.1 0.2 0.1 0 0.12 0
在this page的底部从 Python 2.3 文档中它说: slice objects now have a method indices(length) which, given the le
我在主线程上做一些繁重的计算,这些计算不能在单独的线程上运行。 我想在这些计算运行时在应用程序 UI 上显示一个“忙碌指示器”(即旋转小部件)。因此,我无法在主线程上显示繁忙指示器,因为在这些计算运行
我有一个名为 memory_region 的类,有点像未类型化的 gsl::span (即它本质上是一个 void* 和一个 size_t ),我也将其用于类型删除。因此它有一个 as_span()方
我一直在寻找如何将 Tablayout 中的指示器更改为圆形,就像这样 但我不知道该怎么做,任何帮助! 最佳答案 来自source code ,标签指示器定义为: @dimen/de
我在哪里可以找到可绘制的 Android“向上”按钮以便我可以对其进行自定义?或者它的文件名是什么,以便我可以快速搜索以在 sdk 目录中找到它? 最佳答案 正如您在 default style 中看
我遇到了 ViewPager 的另一个问题,我现在无法用我目前的知识解决它。 我有带 ViewPager 的 TabPageIndicator,在每个选项卡上,我都显示文本。这是简单的 TextVie
我将如何制作一个自定义指示器,该指示器将使用可绘制对象和用于 SwipeRefreshLayout 的自定义动画? 我查看了 SwipeRefreshLayout 的源代码,发现 CircleImag
我是一名优秀的程序员,十分优秀!