Remove name, dtype from pandas output

I have an output file similar to this from the pandas function.

Series([], name: column, dtype: object) 311 race 317 gender Name: column, dtype: object 

I am trying to get output with only the second column, i.e.

 race gender 

deleting the top and bottom rows, the first column. How to do it?

+16
source share
2 answers

You only need the .values attribute:

 In [159]: s = pd.Series(['race','gender'],index=[311,317]) s Out[159]: 311 race 317 gender dtype: object In [162]: s.values Out[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) race gender 
+18
source

DataFrame / Series.to_string

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

If the index is important:

 print(s.to_string()) #311 race #317 gender 
+3
source

Source: https://habr.com/ru/post/985172/


All Articles