- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to get a value from the cell of a Pandas DataFrame?
To get a value from the cell of a DataFrame, we can use the index and col variables.
Steps
Create a two-dimensional, size-mutable, potentially heterogeneous tabular data, df.
Print the input DataFrame, df.
Initialize the index variable.
Initialize the col variable.
Get the cell value corresponding to index and col variable.
Print the cell value.
Example
import pandas as pd df = pd.DataFrame( { "x": [5, 2, 1, 9], "y": [4, 1, 5, 10], "z": [4, 1, 5, 0] } ) print("Input DataFrame is:
", df) index = 2 col = "y" cell_val = df.iloc[index][col] print "Cell value at ", index, "for column ", col, " : ", cell_val index = 0 col = "x" cell_val = df.iloc[index][col] print "Cell value at ", index, "for column ", col, " : ", cell_val index = 1 col = "z" cell_val = df.iloc[index][col] print "Cell value at ", index, "for column ", col, " : ", cell_val
Output
Input DataFrame is: x y z 0 5 4 4 1 2 1 1 2 1 5 5 3 9 10 0 Cell value at 2 for column y: 5 Cell value at 0 for column x: 5 Cell value at 1 for column z: 1
- Related Articles
- How to get the list of column headers from a Pandas DataFrame?
- How to get the row count of a Pandas DataFrame?
- How to get nth row in a Pandas DataFrame?
- How to delete a column from a Pandas DataFrame?
- How to delete a column from Pandas DataFrame
- How to get the sum of a specific column of a dataframe in Pandas Python?
- Python - How to select a column from a Pandas DataFrame
- Python Pandas - How to delete a row from a DataFrame
- Python - How to drop the null rows from a Pandas DataFrame
- Python - Replace values of a DataFrame with the value of another DataFrame in Pandas
- Python Pandas - How to select multiple rows from a DataFrame
- Python Pandas – How to skip initial space from a DataFrame
- How to Get the Position of Max Value of a pandas Series?
- How to Get the Position of Minimum Value of a pandas Series?
- How to access a single value in pandas DataFrame using the integer positions?

Advertisements