0

I am trying to write a Python code which opens a csv file with a list of books, its authors, genre etc, and allows the user to input an ISBN number and based on that it displays the results that match the search.

The csv file has 500 rows and 7 columns separated by comma.

That's my code. Now, the code only shows as output: [1 rows x 7 columns]. But it should display each infomation of the row that matched the ISBN.

# Filter ISBN
df = pd.read_csv('csv_file')
print(df.loc[df['ISBN'].str.contains("3775738193")])
bad_coder
  • 11,289
  • 20
  • 44
  • 72
Thay
  • 3
  • 3

1 Answers1

1

You can filter in an easier way:

print(df[df["ISBN"] == "3775738193"])
Christian Weiss
  • 119
  • 1
  • 14
  • The output is still [1 rows x 8 columns] instead of displaying the entire row with all the info about the book. – Thay Feb 22 '22 at 08:45
  • Can you maybe add an example of your data in the csv? – Christian Weiss Feb 22 '22 at 08:53
  • Of course :) "ISBN,ISBN Image,Thumbnail Image,Title,Author(s),Genre ID,Genre" (these are the titles, then you have 500 rows like that alined with the collumns, like the following) 0,1467122459,1467122459.jpg,http://ecx.images-amazon.com/images/I/51PSyW3NE5L.jpg,Virginia Aviation (Images of Aviation),Roger Connor,0,Arts & Photography – Thay Feb 22 '22 at 08:57
  • The filtering should work with the code and it shows the whole row, correct? What is the info, which is missing? – Christian Weiss Feb 22 '22 at 09:07
  • It is not showing the whole row. That's the problem. – Thay Feb 22 '22 at 09:58
  • I'm a bit confused, because you write The output is "still [1 rows x 8 columns]". which is the complete row? I mocked your data and let it filter with the code above and it shows all the information, column headers, indices and the row information. Can you also post the output that you're getting? – Christian Weiss Feb 22 '22 at 10:18
  • Do you know how can I put an input function so the user can type in the ISBN number? – Thay Feb 22 '22 at 10:21
  • Yes. `user_input = str(input("What ISBN are you looking for?")) ` `def filter_isbn_number(isbn: str) -> None:` `print(df[df["ISBN"] == isbn])` – Christian Weiss Feb 22 '22 at 10:26