简体   繁体   中英

Find equal values in different columns in pandas

I would like to find the intersection between three columns, that is, the equal value in both. I know that these values exist, because graphically the values intersect (within some small error, say 0.01). How can I find this intersection or at least the closest match?

在此处输入图像描述

在此处输入图像描述

data

Can you try this, please?

I have applied a function to calculate the total y distance of the 3 lines for each sample. I assume that the minimum distance is the possible intersection point. Here is my code -

import pandas as pd
df = pd.read_csv('data_Q.csv')

def get_distance(x):
    a = abs(x.Q_upper - x.Q_middle)
    b = abs(x.Q_upper - x.Q_lower)
    c = abs(x.Q_middle - x.Q_lower)
    return a+b+c

df['distance'] = df.apply(lambda x: get_distance(x), axis=1)
get_min = df['distance'].min()
df[df['distance']==get_min]

I found this one

        Q_upper     Q_lower     Q_middle    distance
 2127   79.746342   76.430846   83.151515   13.441338

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