I have a pandas series test set y_test. I want to get its size for statistics.
Using this code :
print(y_test.shape)
I get
(31054,)
I want to get 31054 for calculus.
Thank you for your help!
CodePudding user response:
y_test.shape
gives you a tuple.
So you can do print(y_test.shape)[0]
to get the first element in the there which is the size of the Series.
shape
gives you a tuple because it comes from dataframes which give you the shape of the frame in (rows, columns).
CodePudding user response:
You could either
size = y_test.shape[0]
Which will give first element of the tuple, which is size.
Or you could get it directly using size
attribute or the len()
method.
size = y_test.size
#or
size = len(y_test)
CodePudding user response:
Use len
or Series.size
:
y_test = pd.Series(range(20))
print(len(y_test))
20
print(y_test.size)
20