Pandas:DataFrame數據的基本屬性


一、DataFrame數據的基本屬性

    函數                 返回值            
     values     元素值  
  index 索引
        columns       列名
      dtypes        每個元素的數據類型        
   size      元素的總個數
    ndim  維度數
   shape         數據結構(幾行幾列)      

 

 

 

 

 

 

 

代碼:

import pandas

food_info = pandas.read_csv("food_info.csv")
print(type(food_info))
print("---------")
# print(help(pandas.read_csv))   #  可以用來查看read_csv的幫助文檔

first_rows = food_info.head()   # 默認打印5條記錄
print (first_rows)
print(food_info.head(3))

print("-------------------------")
print(food_info.tail(3))  # 打印后3行數據,默認打印5條記錄

print("-------------------------")
print (food_info.columns)  # 打印出所有的特征變量名

print("-------------------------")
print (food_info.shape)   # 打印數據框food_info的行列結構

print("-------------------------")
print (food_info.dtypes)   # 打印出food_info數據框每個字段的數據類型,numpy的dtype是沒有s的
# pandas的字符串叫做object

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM