I have a series of dataframes inside a dataframe.
The top level dataframe is structured like this :
24hr 48hr 72hr
D1 x x x
D2 x x x
D3 x x x
In each case x is a dataframe created with pandas.read_excel()
One of the columns in each x dataframe has the title 'Average Vessels Length' and there are three entries (i.e. rows, indices) in that column.
What I want to return is the mean value for the column 'Average Vessels Length'. I'm also interested in how to return an particular cell in that column. I know there's a .mean method for pandas dataframes, but I can't figure out the indexing syntax to use it.
Below is an example
import pandas as pd
a = {'Image name' : ['Image 1', 'Image 2', 'Image 3'], 'threshold' : [20, 25, 30], 'Average Vessels Length' : [14.2, 22.6, 15.7] }
b = pd.DataFrame(a, columns=['Image name', 'threshold', 'Average Vessels Length'])
c = pd.DataFrame(index=['D1','D2','D3'], columns=['24hr','48hr','72hr'])
c['24hr']['D1'] = a
c['48hr']['D1'] = a
c['72hr']['D1'] = a
c['24hr']['D2'] = a
c['48hr']['D2'] = a
c['72hr']['D2'] = a
c['24hr']['D3'] = a
c['48hr']['D3'] = a
c['72hr']['D3'] = a
This returns the mean of the values in the column 'Average Vessels Length' :
print b['Average Vessels Length'].mean()
This returns all the values in 24hr, D1, 'Average Vessels Length'
print c['24hr']['D1']['Average Vessels Length']
This doesn't work :
print c['24hr']['D1']['Average Vessels Length'].mean()
And I can't figure out how to access any particular value in c['24hr']['D1']['Average Vessels Length']
Ultimately I want to take the mean from each column of Dx['Average Vessels Length'].mean() and divide it by the corresponding D1['Average Vessels Length'].mean()
Any help would be greatly appreciated.