python
Get a value from DataFrame row using index and column name in pandas
If you want to get the single value from a row using its index and column name you can use at() method of pandas DataFrame.
import pandas as pd
df = pd.DataFrame([[0, 2, 3], [0, 4, 1], [10, 20, 30]],
index=[1, 2, 3], columns=['A', 'B', 'C'])
#index - 3, column_name - 'C'
value = df.at[3, 'C']
print(value) # prints - 30
#this can also written as
value = df.loc[3].at['C']
print( value ) # prints - 30
Was this helpful?
Similar Posts
- Change column orders using column names list - Pandas Dataframe
- Add new row to an existing Pandas DataFrame
- [Pandas] Add new column to DataFrame based on existing column
- Column name as alias name SQLAlchemy
- Pandas - Delete,Remove,Drop, column from pandas DataFrame
- Insert new column with default value in Pandas DataFrame
- [Python] Using inspect.stack() to get module name, path, function name