# 數據挖掘工具pandas（四）DataFrame的屬性

### 一，DataFrame的基本屬性：

shape、dtypes、ndim、index、columns、values、T

``````import pandas as pd
import numpy as np
# from sqlalchemy import create_engine
# engine = create_engine('mysql+pymysql://root:[email protected]:3306/yoyo')
# sql = """select * from role_info;"""
day_data = np.random.normal(0,1,(500,507))
stock_list = ["股票"+ str(i) for i in range(day_data.shape[0])]
date = ["第"+ str(i)+"天" for i in range(day_data.shape[1])]

df = pd.DataFrame(day_data,index=stock_list,columns=date)

# 1,pandas-dataframe的type
# print(type(df))

# 2,shape dataframe的形狀（行數、列數）
# print(df.shape)

# 3,dtypes 每一列的數據類型
# print(df.dtypes)

# 4,ndim 數據維度
# print(df.ndim)

# 5,index 行索引
# print(df.index,df.index[0])

# 6,columns 列索引
# print(df.columns,df.columns[0])

# 7,values 對象值，二維ndarray數組
# print(df.values)

# 8, T , transpose() 兩種轉置
# print(df.T)
print(df.transpose())
``````

### 二，DataFrame的整體情況：

``````head()，tail()，info()，describe()
import pandas as pd
import numpy as np
# from sqlalchemy import create_engine
# engine = create_engine('mysql+pymysql://root:[email protected]:3306/yoyo')
# sql = """select * from role_info;"""
day_data = np.random.normal(0,1,(500,507))
stock_list = ["股票"+ str(i) for i in range(day_data.shape[0])]
date = ["第"+ str(i)+"天" for i in range(day_data.shape[1])]
df = pd.DataFrame(day_data,index=stock_list,columns=date)

# 2,tail(nums) 顯示末尾幾行，默認5行
# print(df.tail(3))

# 3,info() 相關信息概覽：行數，列數，列索引，列非空值個數、列類型、內存佔用
# print(df.info())

# 4,describe() 快速綜合統計帶有數值的結果。計數、均值、標準差、最大值、四分位數、最小值
print(df.describe())
``````