1

I have a pandas data frame as an attribute in Python 2.7, called probs. If I try to execute

log(self.prob['AAA'])

(where AAA is a valid name for one of the columns in the data frame), I get the error

exceptions.TypeError occurred
Message: only length-1 arrays can be converted to Python scalars

but in the interactive IPython, populating df with the same values and executing

log(df0['AAA'])

produces exactly what is needed (data frame column with each value being the log() of the original data).

What is the reason for the difference and is there a way to get the IPython behavior in the regular script?

6
  • You'll need to provide the code you use to load probe in the interpreter and from a file. I'm guessing the difference lies there. Commented Nov 18, 2013 at 17:42
  • 1
    try to print help(log), and help(adataframe['AAA']) or print adataframe['AAA'] in both cases and see if there is a difference Commented Nov 18, 2013 at 17:43
  • @TomAugspurger I'm using exactly the same code to read it in from a database and reshape it -- calling the same getter/formatter functions, no other changes Commented Nov 18, 2013 at 17:45
  • @joaquin that was it, apparently IPython uses a different kind of log() function. Commented Nov 18, 2013 at 17:48
  • @joaquin please write the comment as an answer, i'll gladly accept it. But how can I get that IPython default log() function in my script? Commented Nov 18, 2013 at 17:49

1 Answer 1

1

When IPython is started with the -pylab parameter it loads numpy.log and other numpy functions by default.
It is possible that you are not using numpy.log in your script but maybe math.log, so that it fails

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.