Python Pandas Panel.size
在Pandas中,面板是一个非常重要的三维数据的容器。3个轴的名称是为了给描述涉及面板数据的操作,特别是面板数据的计量经济学分析,提供一些语义上的意义。
在Pandas的Panel.size中,如果是Series,则给出行数。否则,如果是DataFrame,则返回行数乘以列数。
语法: Panel.size
参数: None
返回:返回代表此对象中元素数量的int值。
代码 #1:
# importing pandas module
import pandas as pd
import numpy as np
df1 = pd.DataFrame({'a': ['Geeks', 'For', 'geeks', 'for', 'real'],
'b': [11, 1.025, 333, 114.48, 1333]})
print("df1 is - \n\n", df1)
# Create a 5 * 5 dataframe
df2 = pd.DataFrame(np.random.rand(10, 2), columns =['a', 'b'])
print("df2 is - \n\n", df2)
现在,让我们使用df1和df2的dict创建面板,并获得该面板的尺寸。
data = {'item1':df1, 'item2':df2}
# creating Panel
panel = pd.Panel.from_dict(data, orient ='minor')
print("panel['b'] is - \n\n", panel['b'], '\n')
print("\nSize of panel['b'] is - ", panel['b'].size)
输出:
代码 #2:
# importing pandas module
import pandas as pd
import numpy as np
df1 = pd.DataFrame({'a': ['Geeks', 'For', 'geeks', 'for', 'real'],
'b': [11, 1.025, 333, 114.48, 1333]})
data = {'item1':df1, 'item2':df1}
# creating Panel
panel = pd.Panel.from_dict(data, orient ='minor')
print("panel['b'] is - \n\n", panel['b'], '\n')
print("\nSize of panel['b'] is - ", panel['b'].size)
输出:
代码 #3:
# importing pandas module
import pandas as pd
import numpy as np
df1 = pd.DataFrame({'a': ['Geeks', 'For', 'geeks', 'real'],
'b': [-11, +1.025, -114.48, 1333]})
df2 = pd.DataFrame({'a': ['I', 'am', 'dataframe', 'two'],
'b': [100, 100, 100, 100]})
data = {'item1':df1, 'item2':df2}
# creating Panel
panel = pd.Panel.from_dict(data, orient ='minor')
print("panel['b'] is - \n\n", panel['b'])
print("\nSize of panel['b'] is - ", panel['b'].size)
输出: