In this tutorial, we will introduce how to get a excel value by row and column using python pandas. You can try this example by our steps.
Step 1: Read excel file by python pandas
import pandas as pd excel_file = "excel_test.xlsx" data = pd.read_excel(excel_file) print(data)
We will get:
Step 2: Show all column name
print(type(data.columns), data.columns.tolist())
We will see:
<class 'pandas.core.indexes.base.Index'> ['Name', 'Age']
Step 3: Get value by row and column
From above, we have got column names, we can get all data in one column by:
x = data["Name"]
Here we will get all data in Name column.
However, If we want to get all column value row by row, we can do as follows:
for i in data.index: print(i) v = data.at[i, "Name"] print(v)
Here i is the index number. Run this code, we will get:
0 Tom 1 Jack 2 Steve 3 Ricky