这正是我想要做的: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
和{
Pandas有不同的索引选择机制,其中一些使用整数表示位置,另一些使用标签。您有一个基于字符串的索引,因此需要使用不是位置索引器的索引器。更具体地说,
df.iloc
是严格基于整数的索引。您将希望使用df.loc
。在相关问题 更多 >
编程相关推荐