0

Sorry for a stupid question. I think I need some basics refreshed to answer a problem I'm trying to solve.

Say I'm reading a list in excel like

x y
a team a
b team a
c team b
d team b

If I wanted to look up each x values' y companion using pandas in python, how would I go about this? I'm a little unfamiliar with the process of linking data.

For example looking up c would return team b.

EDIT I'm basically trying to figure out, if y column == team a, then print all of the x values corresponding to team a.

for i in teams:

    if Table.loc[(Table['x']==i)]:
    print(Table.loc[(Table['y'])])
2
  • 2
    I think you're looking for groupby. Commented Jul 25, 2021 at 22:43
  • 1
    It's notable that groupby is iterable. for name, g_df in df.groupby('y'): where name is the name group, team a, team b and g_df is the corresponding DataFrame with those values. Commented Jul 25, 2021 at 22:52

1 Answer 1

1
df.where(df.y=='teama').dropna().x
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.