【发布时间】:2021-04-12 19:49:51
【问题描述】:
我的输入列表是不同数据类型的列表 - 如果数据类型是数字(浮点或整数),我想将输入列表中的索引附加到我的新索引列表中。 我尝试了以下函数,它适用于 int/float 的第一次出现,但随后它返回每个后续浮点数的第一个浮点数的索引以及每个后续整数的第一个整数的索引。
types_list = [str, int, float, datetime.datetime, int, int]
numeric_indices = []
for i in types_list: #now here I check, whether the type of the column is numeric
if i== int or i==float: #if it is indeed of type integer or float which means it would be numeric
print(types_list.index(i))
numeric_indices.append(myindex)
```
【问题讨论】:
-
您真的对迭代类型列表感兴趣吗?遍历数据列表并检查类型似乎更有意义。
标签: python list loops indexing