如何为pandas中的每一行添加标题?

时间:2017-09-16 05:44:31

标签: pandas header line

我有一份蛋白质ID列表,我想添加'> 1','> 2','> 3',... ....'> LEN(列表)'在每一行之前。我怎么能在熊猫中做到这一点?

示例:

$resultArray = [
    'id' => 1,
    'propery_name' => 'Test Property',
    'userData' => [
        'id' => 2,
        'user_name' => 'john'
    ]
];

我希望它是:

protein_ID
KKP65897.1
KKP42119.1
KKP91065.1
OGY93232.1
KUK66913.1

如果我这样做:

protein_ID
>1    
KKP65897.1
>2    
KKP42119.1
>3    
KKP91065.1
>4    
OGY93232.1
>5    
KUK66913.1

我明白了:

for num, line in enumerate(df.protein_ID):
    print(num, line)

我怎样才能做到这一点?谢谢!

1 个答案:

答案 0 :(得分:0)

df[grep("^X[^*]+$", df$secondcolumn),] # test secondcolumn othercolumn #3 3 Xwidfsoid 7 #5 5 Xkdsfhsd 5 #9 9 Xsodifdsifj 5 interleave的{​​{1}}和protein_ID的值

index

如果你只需要它作为列表

df

详细

In [619]: from cytoolz import interleave

In [620]: pd.DataFrame({'protein_ID': list(
         interleave(['>' + (df.index+1).astype(str), df.protein_ID]))})
Out[620]:
   protein_ID
0          >1
1  KKP65897.1
2          >2
3  KKP42119.1
4          >3
5  KKP91065.1
6          >4
7  OGY93232.1
8          >5
9  KUK66913.1
相关问题