在 Pandas 中,Panel是一個非常重要的三維數據容器。 3個軸的名稱旨在為描述涉及麵板數據的操作,尤其是麵板數據的計量分析提供一些語義上的含義。
在Pandas中,Panel.size給出Series的行數。否則,如果是DataFrame,則返回行數乘以列數。
用法: Panel.size
參數:沒有
返回:返回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的字典創建麵板,並獲取該麵板的大小。
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)
輸出:
相關用法
- Python pandas.map()用法及代碼示例
- Python Pandas Series.all()用法及代碼示例
- Python Pandas DatetimeIndex.day用法及代碼示例
- Python Pandas DatetimeIndex.second用法及代碼示例
- Python Pandas Series.sum()用法及代碼示例
- Python Pandas DataFrame.loc[]用法及代碼示例
- Python Pandas Index.where用法及代碼示例
- Python Pandas Series.abs()用法及代碼示例
- Python Pandas Series.get()用法及代碼示例
- Python Pandas Series.ptp()用法及代碼示例
- Python Pandas Series.pop()用法及代碼示例
- Python Pandas Series.max()用法及代碼示例
- Python Pandas Series.min()用法及代碼示例
- Python Pandas Series.pow()用法及代碼示例
- Python Pandas Timestamp.second用法及代碼示例
注:本文由純淨天空篩選整理自Shivam_k大神的英文原創作品 Python | Pandas Panel.size。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。