0

I can print specific Excel sheets on PyCharm (pandas) with no problem. But when trying to count rows inside column (Sample):

import pandas as pd

x = pd.read_excel(r"C:\Users\nan\PycharmProjects\giraffe\GENERA.xlsx", sheet_name=["Sample Info"], engine="openpyxl")

split_values = x["Sample"].unique()

print(split_values)

I get:

  warn(msg)
Traceback (most recent call last):
  File "C:/Users/nan/PycharmProjects/giraffe/genera1.py", line 8, in <module>
    split_values = x["Sample"].unique()
KeyError: 'Sample'

What am I doing wrong?

bad_coder
  • 11,289
  • 20
  • 44
  • 72
rem
  • 1
  • "KeyError: Sample" it did not find column with name Sample can you print `df.columns` output? – Yefet May 08 '21 at 14:55
  • I an trying but cant find where to use df.columns inside my code – rem May 08 '21 at 16:42
  • Welcome to Stack Overflow. `x["Sample"]` is a dictionary retrieval and there isn't a key called `"Sample"` in the dictionary. Use the debugger or a print to check what's inside the `x` [dictionary](https://docs.python.org/3/library/stdtypes.html#dict). – bad_coder May 11 '21 at 12:09

0 Answers0