0

Why does the last two lines give the same output?

import pandas as pd data = { 'name': ['James', 'Billy', 'Bob', 'Amy', 'Tom', 'Harry'], 'rank': [4, 1, 3, 5, 2, 6] } df = pd.DataFrame(data, index=data['name']) print(df ['name'] [df['rank']==int(input())]) print(df[df['rank']==int(input())][‘name’])

20th Jan 2022, 3:48 PM
Nishant Srinet
Nishant Srinet - avatar
1 Answer
0
Because both are valid and both index the same cell 1) indexes the cell by name column 2) indexes the cell by the dataframe row and then picks the column
20th Jan 2022, 3:53 PM
Lisa
Lisa - avatar