Skip to content
Advertisement

How do I remove name and dtype from pandas output

I have output that looks like this:

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

What must be done to remove both Name and dtype at end of output?

Advertisement

Answer

Use the .values attribute.

Example:

In [158]: s = pd.Series(['race','gender'], index=[1,2])

In [159]: print(s)
1      race
2    gender
dtype: object

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

You can convert to a list or access each value:

In [161]: list(s)
Out[161]: ['race', 'gender']
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement