我的输出如下所示:
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
Run Code Online (Sandbox Code Playgroud)
必须做什么才能在输出结束时删除 Name 和 dtype?
.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)
Run Code Online (Sandbox Code Playgroud)
您可以转换为列表或访问每个值:
list(s)
['race', 'gender']
Run Code Online (Sandbox Code Playgroud)
对于带有保留索引的打印,您可以使用.to_string():
df = pd.DataFrame({'a': [1,2,3], 'b': [2.23, 0.23, 2.3]}, index=['x1', 'x2', 'x3'])
s = df.loc[:'x2', 'b']
type(s)
# Out: pandas.core.series.Series
print(s)
# Out:
x1 2.23
x2 0.23
Name: b, dtype: float64 # <- OP is asking to remove "name and dtype"
# solution:
print(s.to_string())
# Out:
x1 2.23
x2 0.23
Run Code Online (Sandbox Code Playgroud)