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
493 views
in Technique[技术] by (71.8m points)

python - iterating through a column in dataframe and creating a list with name of the column + str

I have a dataframe with 2 coulmn, i want to iterate through the column headers, use that value and add a string to it and use it as the name of a list.

rr

resampled=pd.DataFrame() resampled['RAT']=dd1['RAT'] resampled['SAT']=dd1['SAT'] rr=resampled-resampled.shift(1)

for ind, column in enumerate(rr.columns):

name=column+'stuck'
name=[]    
print(name)

I want to get 2 list with names RATstuck SATstuck

THank you!

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

have you tried list comprehension?

[x+'stuck' for x in rr.columns]

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

...