0
Output in Pandas as a Series
Hi everyone! Here's a task: You are given a DataFrame that includes the names and ranks of people. You need to take a rank as input and output the corresponding name column from the DataFrame as a Series. My code: 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']) x = int(input()) res = df.loc[df['rank'] == x] ser = res.iloc[0] print(ser) My output: name Bob rank 3 Name: Bob, dtype: object Expected output: Bob Bob Name: name, dtype: object How it might be improved? How to get Bob_Bob?))
2 Respuestas
0
Actually, I have no clue how to pass this challenge. The expected output is weird.
but the task supposes to be simple, maybe I missed something.
Could somebody give me a prompt?
The second variant of a code >>>
x = int(input())
res = df.loc[df['rank'] == x]
print(res.iloc[[0], [0]])
gives us>>>
input: 3
output:
name
Bob Bob))
0
Guess what?
a = int(input())
b = df.loc[df['rank'] == a]
print(b['name'])
For goodness sake