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,
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
CodePudding user response:
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))