close

How do I remove name and dtype from pandas output

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How do I remove name and dtype from pandas output in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How do I remove name and dtype from pandas output?

  1. How do I remove name and dtype from pandas output?

    For printing with preserving index you can use .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

  2. I remove name and dtype from pandas output

    For printing with preserving index you can use .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

Method 1

For printing with preserving index you can use .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

Method 2

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)

You can convert to a list or access each value:

list(s)
['race', 'gender']

Summery

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read