1

I have a pandas DataFrame and I would like to make a new column with the same string in each row.

Currently I'm doing this.

tag=[]
for x in xrange(len(preds)): #preds is a np.array, same length of df
    tag.append('MY STRING')
 df['TAG']=tag

I know there must be a smarter way to do this.

Any help is appreciated.

2

1 Answer 1

2

df['TAG'] = ['MY STRING'] * len(preds)

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.