0

I am trying to iteratively add values to rows and columns through loops. If i increase the number of rolls in this case, loop should add new 1000 values to columns for each specific number of rolls creating new rows each with 1000 columns. However, I am getting the error "ValueError: setting an array element with a sequence."

import random
import pandas as pd
A = [2,6,7]
B = [1,5,9]
C = [3,4,8]
a = pd.DataFrame(); b = pd.DataFrame()
N = 1000
rolls = -1
while rolls != 0:
    rolls += 1
    for i in range(N):
        a.at[rolls,i] = [random.choice(A)]
        b.at[rolls,i] = [random.choice(B)]

1 Answer 1

3

Set scalar instead one element list:

a.at[rolls,i] = random.choice(A)
b.at[rolls,i] = random.choice(B)
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.