-4

Suppose I have an excel sheet

Name Id Message
Alex 123 Hello
Mike 453 Hey There
Andy 865 How are you?
Ricky 987 Hi

I want to get an individual cell and use it as a variable in python First I want to get Alex, use it, then get Mike and so on

Can someone help me with this.

Pranav Hosangadi
  • 23,755
  • 7
  • 44
  • 70

1 Answers1

0

You could use pandas for that.

import pathlib
import pandas

excel_file_path = pathlib.Path('my.xlsx')

df = pandas.read_excel(excel_file_path)

print(df.Name)  # something like ['Alex', 'Mike', 'Andy', 'Ricky']

This example assumes that there is only one sheet in the Excel file. The data starts at the first cell (A1) and the first row includes the column names.

Another package you could use is openpyxl.

buhtz
  • 10,774
  • 18
  • 76
  • 149