使用索引标签创建新的Pandas数据帧(iloc错误:Flexible类型)

2024-09-28 22:22:21 发布

您现在位置:Python中文网/ 问答频道 /正文

这正是我想要做的:Creating new pandas DataFrame from existing DataFrame and index

我没有索引号,而是用标签来索引。。。在

伪代码:

want_these_indices = ['A1BG',
 'A4GALT',
 'AAAS',
 'AADAT',
 'AAK1',
 'AAMP',
 'AANAT',
 'AARS',...]

sorted(DF.index)
['A1BG',
 'A4GALT',
 'AAAS',
 'AACS',
 'AADAT',
 'AAGAB',
 'AAK1',
 'AAMP',
 'AANAT',
 'AARS',
 'AARS2',...]

但当我 TypeError: cannot perform reduce with flexible type我甚至试过DF.iloc[want_these_indices,:]

我认为,可能是因为有些指数是浮动的,但它们都是字符串。在DF.index和{}中


Tags: creatingdataframedfindexwantindicesthesea4galt
1条回答
网友
1楼 · 发布于 2024-09-28 22:22:21

Pandas有不同的索引选择机制,其中一些使用整数表示位置,另一些使用标签。您有一个基于字符串的索引,因此需要使用不是位置索引器的索引器。更具体地说,df.iloc是严格基于整数的索引。您将希望使用df.loc。在

相关问题 更多 >