Remove name, dtype from pandas output of dataframe or series Remove name, dtype from pandas output of dataframe or series python python

Remove name, dtype from pandas output of dataframe or series


DataFrame/Series.to_string

These methods have a variety of arguments that allow you configure what, and how, information is displayed when you print. By default Series.to_string has name=False and dtype=False, so we additionally specify index=False:

s = pd.Series(['race', 'gender'], index=[311, 317])print(s.to_string(index=False))#   race# gender

If the Index is important the default is index=True:

print(s.to_string())#311      race#317    gender

Series.str.cat

When you don't care about the index and just want the values left justified cat with a '\n'. Values need to be strings, so convert first if necessary.

#s = s.astype(str)print(s.str.cat(sep='\n'))#race#gender


You want just the .values attribute:

In [159]:s = pd.Series(['race','gender'],index=[311,317])sOut[159]:311      race317    genderdtype: objectIn [162]:s.valuesOut[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)racegender


Sometimes I do print(*s, sep='\n'):

s = pd.Series(['race', 'gender'], index=[311, 317])print(*s, sep='\n')

gives

racegender