Skip to content
Advertisement

How can I take the log of a column in Python using Numpy?

I have the the following df:

0        4.20
1        6.30
2       74.90
3       83.45
4       17.19
5       74.34
6     1717.73
7      139.05
8      753.36
9        4.54
10      60.07
Name: exports, dtype: float64

I would like take logs of the whole column, but when I try:

import numpy as np
lexports=np.log(df['exports'])

..I get the following error: AttributeError: 'int' object has no attribute 'log'

How can I fix this? I looked up other threads. They seem to explore causes, but don’t provide solutions.

Advertisement

Answer

This error means that you have used np as name for some other variable (of type integer)

You can run

del np

and

import numpy as np 

again, and it will work

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement