我的输出看起来像这样:
nutrition_info_256174499 = df1.loc[:"Salt" , "%Reference Intake*"]
print (nutrition_info_256174499)
Typical Values
Energy 5%
Fat 1%
of which saturates 1%
Carbohydrates 7%
of which sugars 2%
Fibre -
Protein 7%
Salt 6%
Name: %Reference Intake*, dtype: object
必须执行什么操作才能在输出末尾同时删除Name和dtype?
答案 0 :(得分:0)
.values
属性。示例:
s = pd.Series(['race','gender'],index=[1,2])
print(s)
Out[159]:
1 race
2 gender
dtype: object
s.values
array(['race', 'gender'], dtype=object)
您可以转换为列表或访问每个值:
list(s)
['race', 'gender']
答案 1 :(得分:0)
要使用保留索引进行打印,可以使用.to_string()
:
df = pd.DataFrame({'a': [1,2,3], 'b': [2.23, 0.23, 2.3]}, index=['x1', 'x2', 'x3'])
print(df.loc[:'x2', 'b'].to_string())
# Out:
x1 2.23
x2 0.23
答案 2 :(得分:0)
print(nutrition_info_256174499.to_string())
应删除印刷品中的名称:%Reference Intake *,dtype:object