0

I found this post, which answers the question, but I think there should be an easier way to do that.

Here is my example: From the object boston, I want to know if the attibutes are strings or arrays. a) gives me the names. b) gives me obviously not the info I want to have c) gives me what I want to have But I think that option c) is overcomplicated, and there should be cleaner way to do that. Any ideas?

from sklearn.datasets import *
boston = load_boston()

a= dir(boston)
b=[type(x) for x  in boston]
c=[type(getattr(boston, name)).__name__ for name in dir(boston) ]

print(a,"\n", b,"\n",c)

Out:

['DESCR', 'data', 'feature_names', 'filename', 'target'] 
[<class 'str'>, <class 'str'>, <class 'str'>, <class 'str'>, <class 'str'>] 
['str', 'ndarray', 'ndarray', 'str', 'ndarray']
Kolibril
  • 1,096
  • 15
  • 19

1 Answers1

1
print([x for x in boston])
print([type(boston[x]) for x in boston])

Out:

['data', 'target', 'feature_names', 'DESCR', 'filename']
[<class 'numpy.ndarray'>, <class 'numpy.ndarray'>, <class 'numpy.ndarray'>, <class 'str'>, <class 'str'>]
jayden
  • 26
  • 2