Python 从熊猫输出中删除名称、数据类型
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29645153/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 04:49:46 来源:igfitidea点击:
remove name, dtype from pandas output
提问by pam
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?
通过删除顶行和底行,第一列。我怎么做?
采纳答案by EdChum
You want just the .values
attribute:
你只想要.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
回答by ALollz
DataFrame
/Series.to_string
DataFrame
/Series.to_string
s = pd.Series(['race', 'gender'], index=[311, 317])
print(s.to_string(index=False))
# race
# gender
If the Index is important:
如果索引很重要:
print(s.to_string())
#311 race
#317 gender