Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to call upon csv file on pandas python using words

Just to simplified the problem I make a list of fruits, how I ranked them and their colour, and I want to call them with their name.

import pandas as pd

Data = pd.read_csv("Fruits.csv")
df = pd.DataFrame(Data)
Fruits = int(input("Insert fruit name: "))
print(df.loc[Fruits])

And here is the csv file

Fruit,Rating,Colour
Apple, 5/10, Red
Banana, 7/10, Yellow
Grapes, 10/10, Purple
Orange, 9/10, Orange

When I run the program, when I put in the number 0 in it,

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Insert fruit name: 0
Fruit     Apple
Rating     5/10
Colour      Red
Name: 0, dtype: object

And I dont want that, I want when I put

Insert fruit name: Apple
Fruit     Apple
Rating     5/10
Colour      Red

Thanks in advance

>Solution :

You need rename:

import pandas as pd

Data = pd.read_csv("Fruits.csv")
df = pd.DataFrame(Data)
Fruits = input("Insert fruit name: ")
print(df.loc[df['Fruit'] == Fruits].rename(None))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading