1

I'm using Python3.x. The bricks = [] the data is dataframe single element array which contains number and some negative numbers

for delta in data:
    if delta > 0:
        bricks.extend([1] * delta)
    else:
        bricks.extend([-1] * abs(delta))

The above code throws error, without affecting the outcome how to correct the code which will run without errors

The error here is:

bricks.extend([1] * delta) TypeError: 'numpy.float64' object cannot be interpreted as an integer

Note :Community, before giving negative numbers, marked as duplicate provide a solution and then mark as you wish.

4
  • tried this as well another error in that way for delta in int(data): TypeError: only size-1 arrays can be converted to Python scalars Commented Jan 19, 2018 at 11:24
  • 1
    This doesn't look like pandas to me, unless you can provide some input and expected output. Basically, a minimal reproducible example. Commented Jan 19, 2018 at 11:25
  • bricks = dff[dff['bricks'] != 0]['bricks'].values this is passed as data Commented Jan 19, 2018 at 11:27
  • That doesn't look very good, as far as good pandas practices goes. Also, I can't understand what you want. Because I don't have your data, and you haven't explained anything. Gosh, and you're defensive about getting downvotes... Commented Jan 19, 2018 at 11:29

1 Answer 1

1

I think you should try

    bricks.extend([1. * delta])

Considering that your "delta" is a simple value(numpyFloat or something like that) and you want to extend the list with a list of 1 value.

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

1 Comment

There is no point in guessing. I interpret the OP question as data = [2, -2, 3] -> bricks = [1, 1, -1, -1, 1, 1, 1]. But who knows. He hasn't provided a reproducible example.

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.