October 22, 2024
Chicago 12, Melborne City, USA
python

how to extract a cell value from a dataframe?


I am trying to extract a cell value from a dataframe, then why I always get a series instead of a value.

For example:

df_test=pd.DataFrame({'Well':['test1','test2','test3'],'Region':['east','west','east']})
df_test

Well    Region
0   test1   east
1   test2   west
2   test3   eas

well="test2"
region_thiswell=df_test.loc[df_test['Well']==well,'Region']
region_thiswell
1    west
Name: Region, dtype: object

I am expecting variable of region_thiswell is equal to ‘west’ string only. Why I am getting a series?

Thanks



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video