Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (18.4k points)

The code I am using for converting the float into int is as follows:

users.age.mean().astype(int64)

In the code, the user is the name of the data frame and the user is the column in the data frame.

ERROR:

AttributeError                            

Traceback (most recent call last)

<ipython-input-29-10b672e7f7ae> in <module>

----> 1 users.age.mean().astype(int64)

AttributeError: 'float' object has no attribute 'astype'

1 Answer

0 votes
by (36.8k points)
edited by

The users.age.mean() returns a float, not a series. Floats don't have astype, only pandas series.

Try:

x = numpy.int64(users.age.mean())

Or:

x = int(users.age.mean())

If you want to know more about the Data Science then do check out the following Data Science which will help you in understanding Data Science from scratch

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...