从 pandas 输出中删除名称,dtype [英] remove name, dtype from pandas output

查看:97
本文介绍了从 pandas 输出中删除名称,dtype的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从pandas函数中获得了这样的输出文件.

I have output file like this from a pandas function.

Series([], name: column, dtype: object)
311     race
317     gender
Name: column, dtype: object

我正在尝试仅在第二列即

I'm trying to get an output with just the second column, i.e.,

race
gender

通过删除第一行的顶部和底部行.我该怎么办?

by deleting top and bottom rows, first column. How do I do that?

推荐答案

您只需要.values属性:

In [159]:

s = pd.Series(['race','gender'],index=[311,317])
s
Out[159]:
311      race
317    gender
dtype: object
In [162]:

s.values
Out[162]:
array(['race', 'gender'], dtype=object)

您可以转换为列表或访问每个值:

You can convert to a list or access each value:

In [163]:

list(s)
Out[163]:
['race', 'gender']

In [164]:

for val in s:
    print(val)
race
gender

这篇关于从 pandas 输出中删除名称,dtype的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆