How do I convert a pandas data frame with 1 row, 1 column into a scalar value?
import pandas as pd
data = {'col1': 1}
df = pd.DataFrame(data=d)
How do I convert a pandas data frame with 1 row, 1 column into a scalar value?
import pandas as pd
data = {'col1': 1}
df = pd.DataFrame(data=d)
You can use iat to access scalar elements specifying the location by integer (i.e. 0,0
for the top left element, as opposed to at which would take the row and columns labels rather than integer index).
So if you only have one element in your dataframe, df.iat[0,0]
will get it for you.
In [139]: import pandas as pd
In [140]: df = pd.DataFrame(data=[1], columns=['col1'])
In [141]: df.iat[0,0]
Out[141]: 1
In [143]: df
Out[143]:
col1
0 1