1

I have a list arr1 in python -

for row in arr1:
    print(row)

This gives the contents as follows-

['1', '0', '86.0', '49.0', '70.0', 'NA', '87.0', 'NA', '0']
['1', '4320', 'NA', 'NA', '70.0', 'NA', 'NA', 'NA', '0']
['1', '5646', '91.0', '58.0', 'NA', 'NA', 'NA', '96.6', '1']
['1', '5703', '140.0', '73.0', '91.0', '32.0', 'NA', 'NA', '1']
['1', '6342', '139.0', '90.0', '107.0', '29.0', '101.0', 'NA', '1']
['1', '6609', '152.0', '75.0', '109.0', '30.0', '101.0', 'NA', '1']
['1', '6894', '140.0', '79.0', '84.0', 'NA', '98.0', 'NA', '1']
['1', '6957', '140.0', '72.0', '108.0', '31.0', '101.0', 'NA', '1']

Now, I want to add some columns to this based upon the values in first two columns. For example if first column is 1 and second column is 4320 add a new column with value 1 otherwise add 0. I am new to python and not sure how to do this.

0

1 Answer 1

4
for i,row in enumerate(arr1):
    if row[0]=='1' and row[1]=='4320':
        val = '1'
    else:
        val = '0'
    arr1[i].append(val)
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.