How can I fill a DataFrame column with a list of e.g. 2 values in Pandas Python? -


that question quite simple, python beginner:

i want create dataframe column given dataframe = df , fill list of values. it's absolutely clear me how fill 1 value:

df["xyz"] = 1 

but doesn't work:

df["xyz"] = [0,1] 

i want fill column 0,1,0,1,0,1...

do know how solve that? longer lists?

using itertools.cycle & itertools.islice:

>>> itertools import cycle, islice >>> df['xyz'] = list(islice(cycle([0, 1]), len(df))) 

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -