A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://stackoverflow.com/questions/62318682/get-pandas-datframe-values-by-key below:

python - get pandas datframe values by key

I have this dataframe,

import pandas as pd

one = pd.DataFrame({
    'id':[1,2,3,4,5],
    'Name': ['Alex', 'Amy', 'Allen', 'Alice', 'Ayoung'],
    'subject_id':['sub1','sub2','sub3','sub4','sub5'],
    'Marks_scored':[98,90,87,69,78],
    'Rank': [1,1,2,10,7]})

two = pd.DataFrame({
    'id':[1,2,3,4,5],
    'Name': ['Billy', 'Brian', 'Bran', 'Bryce', 'Betty'],
    'subject_id':['sub1','sub2','sub3','sub7','sub8'],
    'Marks_scored':[89,80,79,97,88],
    'Rank': [1,2,5,1,2]})

I have concatenated these two dataframes like this.

df = pd.concat([one,two],keys=['x','y'])

Now I want only the values from key 'x' only. How can I achieve that?


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4