Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
268 views
in Technique[技术] by (71.8m points)

pandas - Creating dynamically generated column in dataframe

name = ['x', 'y', 'z']
for i in range(0,3):
    df = pd.DataFrame({'Name': name[i]})

I have just started programming.

I am getting the following error --

If using all scalar values, you must pass an index.

Even if I write :

df = pd.DataFrame([{'Name': name[i]}])

this gives a column with last value only.

I want a column with all the values in an array. Can someone help me with this?

question from:https://stackoverflow.com/questions/65901705/creating-dynamically-generated-column-in-dataframe

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...