简体   繁体   中英

How to search through pandas data frame row by row and extract variables

I am trying to search through a pandas dataframe row by row and see if 3 variables are in the name of the file. If they are in the name of the file, more variables are extracted from that same row. For instance I am checking to see if the concentration, substrate and the number of droplets match the file name. If this condition is true which will only happen one as there are no duplicates, I want to extract the frame rate and the time from that same row. Below is my code:

excel_var = 'Experiental Camera.xlsx'
workbook = pd.read_excel(excel_var, "PythonTable")
workbook.Concentration.astype(int, errors='raise')

for index, row in workbook.iterrows():
    if str(row['Concentration']) and str(row['substrate']) and str(-+row['droplets']) in path_ext:
        Actual_Frame_Rate = row['Actual Frame Rate']
        Acquired_Time = row['Acquisition time']

Attached is a example of what my spreadsheet looks like and what my Path_ext is

At the moment nothing is being saved for the Actual_Frame_Rate and I don't know why. I have attached the pictures to show that it should match. Is there anything wrong with my code /. is there a better way to go about this. Any help is much appreciated. 在此处输入图像描述 在此处输入图像描述

So am unsure why this helped but fixed is by just combining it all into one string and matching is like that. I used the following code:

for index, row in workbook.iterrows():
    match = 'water(' + str(row['Concentration']) + '%)-' + str(row['substrate']) + str(-+row['droplets'])
    # str(row['Concentration']) and str(row['substrate']) and str(-+row['droplets'])
    if match in path_ext:
        Actual_Frame_Rate = row['Actual Frame Rate']
        Acquired_Time = row['Acquisition time']

This code now produces the correct answer but am unsure why I can't use the other method as of yet.

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