简体   繁体   中英

Iterate over rows/columns and extract values to a different dataframe

在此处输入图像描述

Suppose i have 2 dataframe. df is the master list. df1 is a reference table.

i need to iterate over df1['3A'], and if the string match, i will need to extract values/string in the row and plug into corresponding column of df.

the output: 在此处输入图像描述

what would be the best method to go about.

if both df have the same size the you can iterate just like a regular matrix

# go through the rows
for row in range(total_rows):
    # go through the columns
    for column in range(total_columns):
        #make the condition if they match
        if df[row][column] == df1[row][column]:
            # now just assign the value from df1 to df
            df[row][column] = df1[row][column]

i hope this solves your issue:)

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