How do I get get the value of a cell & store into variable with Pandas? How do I get get the value of a cell & store into variable with Pandas? pandas pandas

How do I get get the value of a cell & store into variable with Pandas?


The following should work:

latitude = latitude.values[0]

.values accesses the numpy representation of a pandas.DataFrameAssuming your code latitude = df['latitude'] really results in a DataFrame of shape (1,1), then the above should work.


import pandas as pd# Create a dataframedf = pd.DataFrame([                   {'First':'Bill'                    ,'Last':'Thompson'                    ,'AcctNum':'0001'                   ,'AcctValue':100},                   {'First':'James'                    ,'Last':'Winters'                    ,'AcctNum':'0002'                    ,'AcctValue':200},                   {'First':'Anna'                    ,'Last':'Steele'                    ,'AcctNum':'0003'                    ,'AcctValue':300},                   {'First':'Sean'                    ,'Last':'Reilly'                    ,'AcctNum':'0004'                    ,'AcctValue':400}                   ])# Select data and set it to a variableaccount_value = df.loc[df['AcctNum'] == '0003']['AcctValue'].values[0]print account_value


You can Try something like this. This works for me.DF.iloc[2].Name

Here 2 is the row , and the Name is the column name.You can do an iteration in while loop after that.

Hope this helps.