You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在数据表中另外两列值相等时获取指定列的对应值?

Hey there! Let's figure out how to get the user value where the center and right columns have matching values. Based on your sample data, here are a couple of common approaches depending on the tool you're using:

Using SQL (for relational databases)

If you're querying a database table, a simple SELECT statement with a WHERE clause will do the trick. Just filter rows where center equals right, then select the user column:

SELECT user
FROM your_table_name
WHERE center = right;

In your sample data, this query will return mary—since her center (1000) and right (1000) values match—while Jane's mismatched values get excluded.

Using Python Pandas (for in-memory DataFrames)

If you're working with a pandas DataFrame, here's how you can achieve the same result:

First, let's set up your sample data:

import pandas as pd

# Create the sample DataFrame
data = {
    'user': ['mary', 'jane'],
    'center': [1000, 9999],
    'right': [1000, 2222]
}
df = pd.DataFrame(data)

Then filter the rows where center equals right and extract the user value:

# Get all matching users (as a list)
matching_users = df[df['center'] == df['right']]['user'].tolist()

# If you only need the first match (like in your sample)
print(matching_users[0])  # Output: mary

This will give you exactly the user you're looking for when the two columns have equal values.

内容的提问来源于stack exchange,提问作者nerd

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 00:12:40