Skip to content
Fix Code Error

How to get a value from a cell of a dataframe?

March 13, 2021 by Code Error
Posted By: Anonymous

I have constructed a condition that extract exactly one row from my data frame:

d2 = df[(df['l_ext']==l_ext) & (df['item']==item) & (df['wn']==wn) & (df['wd']==1)]

Now I would like to take a value from a particular column:

val = d2['col_name']

But as a result I get a data frame that contains one row and one column (i.e. one cell). It is not what I need. I need one value (one float number). How can I do it in pandas?

Solution

If you have a DataFrame with only one row, then access the first (only) row as a Series using iloc, and then the value using the column name:

In [3]: sub_df
Out[3]:
          A         B
2 -0.133653 -0.030854

In [4]: sub_df.iloc[0]
Out[4]:
A   -0.133653
B   -0.030854
Name: 2, dtype: float64

In [5]: sub_df.iloc[0]['A']
Out[5]: -0.13365288513107493
Answered By: Anonymous

Related Articles

  • Combining items using XSLT Transform
  • Change column type in pandas
  • Most effective way to parse JSON Objects
  • assign flexbox cells the same width
  • Pandas - Get first row value of a given column
  • How to use dynamic column names in an UPDATE…
  • Using Auto Layout in UITableView for dynamic cell…
  • How are iloc and loc different?
  • Can't stratify output in a customized way
  • C++ template,typename and operator
  • How to return a list from a pos tag column?
  • adding pandas df to dask df
  • Creating a dataframe of two loops using haversine…
  • Why doesn't the height of a container element…
  • How to merge multiple sheets and rename colomn names…
  • Set value for particular cell in pandas DataFrame with iloc
  • Pandas Merging 101
  • Create a day-of-week column in a Pandas dataframe…
  • Rolling Average Home and Away
  • Importing Pandas gives error AttributeError: module…
  • Pandas - Reshape a dataframe columns based on…
  • SQL- Ignore case while searching for a string
  • Creating a dataframe of many loops within loops for…
  • Replacing nested loops over a dataframe with…
  • Dataframe count set of conditions passed by several…
  • Truth value of a Series is ambiguous. Use a.empty,…
  • Type of panda.Series
  • Efficient way to apply multiple filters to pandas…
  • Get first row of dataframe in Python Pandas based on…
  • Draw in Canvas by finger, Android
  • How do I expand the output display to see more…
  • Fetching the data from webpage with .cms extension
  • Access PostgreSQL hstore keys and values in Python…
  • How to convert array column to int array in Pandas?
  • Jquery how to use this in a event datatable generated td row
  • Unable to get Notification pop-up
  • Make the size of a heatmap bigger with seaborn
  • Calculate repeat purchase probability
  • Pandas multi-index unstack to single row
  • Python Pandas - Time Series Find Index of Previous Row
  • MySQL remove all whitespaces from the entire column
  • Merge 2 dataframes of different sizes after a…
  • Pandas pivot_table: filter on aggregate function
  • how to add a DataFrame to some columns of another DataFrame
  • easiest way to extract Oracle form xml format data
  • Pandas - DF with lists - find all rows that match a…
  • Remove similar tuple from dictionary of tuples
  • Numbering rows in pandas dataframe (with condition)
  • how to split dataframe cells using delimiter into…
  • How do I split out a multi-index dataframe with a…
  • Is there a better, cleaner way to write this…
  • Convert pandas.Series from dtype object to float,…
  • How to save a pandas DataFrame table as a png
  • How to update dataframe.ix code when refering to dates
  • Pandas read_csv low_memory and dtype options
  • Mysql get spefic word before/after
  • How to make a simple collection view with Swift
  • pandanic way of inserting df[col].str.extract()…
  • How to vertically align an image inside a div
  • Pandas counting/adding values by date and id
  • Backbone DOM events firing multiple times
  • "Large data" workflows using pandas
  • How to join dataframe?
  • Construction and ordering of nested and template if=…
  • Interdependent properties in Vue.js
  • How do I divide values across dataframes in pandas?
  • Convert Pandas Series to DateTime in a DataFrame
  • Pandas series remains the same after appending to it…
  • Why does .loc not always match column names?
  • How to combine the data from two different…
  • Get total of Pandas column
  • How to get device make and model on iOS?
  • Splitting dataframe into multiple dataframes
  • I have just started learning function pointers in C…
  • Highcharts make positive numbers in ranges of green…
  • Find row where values for column is maximal in a…
  • How do SO_REUSEADDR and SO_REUSEPORT differ?
  • Async image loading from url inside a UITableView…
  • What do these operators mean (** , ^ , %, //)?
  • Merge list of results into a single variable with Python
  • POI Word Unable to merge newly created cell vertically
  • Running a statistical test column wise in a…
  • Calculate count of a numeric column into new columns…
  • Python Pandas: Get index of rows which column…
  • How to Incrementally Increase from a Starting Value…
  • Function is Producing an Compile Erorr
  • pandas: merge (join) two data frames on multiple columns
  • Table fixed header and scrollable body
  • Detect whether a Python string is a number or a letter
  • Get Cell Value from Excel Sheet with Apache Poi
  • how to convert a panda dataframe column containing…
  • Android Image View Pinch Zooming
  • python pandas extract year from datetime: df['year']…
  • What does "Fatal error: Unexpectedly found nil while…
  • How to fix Python Numpy/Pandas installation?
  • How to get a value from a Pandas DataFrame and not…
  • Concatenate rows of two dataframes in pandas
  • Updating a deep component when prop changes in Svelte
  • In unity 2D c# how to rotate an object like geometry dash?
  • Is it possible to use bs4's find_all with a regex in…

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

Calculate difference between two dates (number of days)?

Next Post:

How to install the JDK on Ubuntu Linux

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

.net ajax android angular arrays aurelia backbone.js bash c++ css dataframe ember-data ember.js excel git html ios java javascript jquery json laravel linux list mysql next.js node.js pandas php polymer polymer-1.0 python python-3.x r reactjs regex sql sql-server string svelte typescript vue-component vue.js vuejs2 vuetify.js

  • you shouldn’t need to use z-index
  • No column in target database, but getting “The schema update is terminating because data loss might occur”
  • Angular – expected call-signature: ‘changePassword’ to have a typedeftslint(typedef)
  • trying to implement NativeAdFactory imports deprecated method by default in flutter java project
  • What should I use to get an attribute out of my foreign table in Laravel?
© 2022 Fix Code Error