how do I return Max Test result + corresponding student name from an excel dataset? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: how do I return Max Test result + corresponding student name from an excel dataset? (/thread-36095.html) |
how do I return Max Test result + corresponding student name from an excel dataset? - sean1 - Jan-16-2022 I have a dataset with column headers Student name, ID, Nationality and several test scores (one col per subject.) I have converted the columns to list and am able to get the max score but not sure as to how I can get the max test score for a subject + the students name. Thanks in advance! RE: how do I return Max Test result + corresponding student name from an excel dataset? - jefsummers - Jan-16-2022 Two things. First, as always in this site, show us your code, what you have done so far! Second, we need to know the format of the data. You say a list, how is that formatted? A list of what? You also mention a dataset. Pandas (I hope)? RE: how do I return Max Test result + corresponding student name from an excel dataset? - sean1 - Jan-16-2022 (Jan-16-2022, 04:52 PM)jefsummers Wrote: Two things. First, as always in this site, show us your code, what you have done so far! yes in pandas, converted the excel file to list using pandas as pd RE: how do I return Max Test result + corresponding student name from an excel dataset? - snippsat - Jan-16-2022 You should follow jefsummers advice. (Jan-16-2022, 04:52 PM)jefsummers Wrote: show us your code, what you have done so far! sean1 Wrote:yes in pandas, converted the excel file to list using pandas as pdIt should no be converted a list,maybe you mean DataFrame? import pandas as pd df = df.to_excel('file_name.xlsx', index=False) Ok to show a example that can help,as you see it easy to make example code that other can run. import pandas as pd from io import StringIO data = StringIO('''\ Movie,Year The Godfather,1972 Seven,1995 Jaws,1975 Lawrence of Arabia,1962''') df = pd.read_csv(data, sep=',') # A DataFrame this is what all data that comes into Pandas become >>> df Movie Year 0 The Godfather 1972 1 Seven 1995 2 Jaws 1975 3 Lawrence of Arabia 1962 >>> >>> year_max = df['Year'] >>> year_max.max() 1995 >>> >>> # To get max value and whole row >>> year = df[df['Year']==df['Year'].max()] >>> year Movie Year 1 Seven 1995 |