Tommy
Tommy

Reputation: 51

Getting the the value of a row in a specific column

given is a excel sheet with the following details:

   Country    Name       Year
   
   Germany    Lisa       1992
   Spain      Sofia      1992
   USA        Thomas     1992
   Sweden     Hubert     1994
   Germany    Jossy      1995

Now I want to have a python function where you use the year as a parameter and it gives returns you back the values of the row.

So for example def giveDetails(1992) then it should return me Germany Lisa and Span Sofia

Or giveDetails(1994) --> return Sweden , Hubert.

I know that you have to convert in in a Pandas dataframe and iterate through the rows and columns but I don't know how to get the value of the the columns "country" and "name" while the value of "year" is given.

I hope someone can help. Thanks in advance guys!

Upvotes: 0

Views: 44

Answers (1)

Ade_1
Ade_1

Reputation: 1486

You can filter using pandas

fil_year= df['year']== 'the year you want'

df.loc[fil_year]

Upvotes: 1

Related Questions