简体   繁体   中英

How can I take values from a certain range of cells and copy it to a certain range in the dataframe in Python?

Good Day Everyone!

So got to do something probably a million times in this project which I just don't understand.

For example look at the dataset here:用户名列

What I most specifically need are the first 20 usernames so from index 0:20 and these need to go to the Sponsor column which can be seen here:

我需要复制这些用户名的赞助商专栏

What this dataset does is build a genealogy that I'm trying to achieve here.

Kindly help if you can

Try this and let us know your output

u_names = df.Username.values[:20]
for idx, row in df.loc[20:40].iterrows():
    row['MainSponsor'] = u_names[idx]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM