網站首頁 編程語言 正文
Pandas所支持的數據類型:?
Python,numpy都有自己的一套數據格式,它們之間的對應關系可參考如下表格:
pandas默認的數據類型是int64,float64。
1.數據框字段類型查看:df.dtypes
?數據框td_link_data如下
print(td_link_data)
?? ? 鏈路ID ?管理域 ? 日期 ? 時間 ?上行速率Mbps ?上行對比速率Mbps ?下行速率Mbps ?下行對比速率Mbps ?上行丟棄速率Mbps ?
0 ? ? 500 ?10001 ?20210609 ?10 ? ? 0.000 ? ? ? ? 0.011 ? ? ? ? ? ? ?0.000 ? ? ? ? ?0.001 ? ? ? ? ? ? 0.0 ? ? ? ?
1 ? ? 500 ?10001 ?20210609 ?11 ? ? 0.000 ? ? ? ? 0.007 ? ? ? ? ? ? ?0.000 ? ? ? ? ?0.000 ? ? ? ? ? ? 0.0 ? ? ? ?
2 ? ? 500 ?10001 ?20210609 ?12 ? ? 0.000 ? ? ? ? 0.028 ? ? ? ? ? ? ?0.000 ? ? ? ? ?0.002 ? ? ? ? ? ? 0.0 ? ? ? ?
3 ? ? 500 ?10001 ?20210609 ?13 ? ? 0.000 ? ? ? ? 0.056 ? ? ? ? ? ? ?0.000 ? ? ? ? ?0.003 ? ? ? ? ? ? 0.0 ? ? ? ?
4 ? ? 500 ?10001 ?20210609 ?14 ? ? 0.000 ? ? ? ? 0.062 ? ? ? ? ? ? ?0.000 ? ? ? ? ?0.003 ? ? ? ? ? ? 0.0 ? ? ? ?
5 ? ? 500 ?10001 ?20210609 ?15 ? ? 0.000 ? ? ? ? 0.074 ? ? ? ? ? ? ?0.000 ? ? ? ? ?0.005 ? ? ? ? ? ? 0.0 ? ? ? ?
6 ? ? 500 ?10001 ?20210609 ?16 ? ? 0.000 ? ? ? ? 0.061 ? ? ? ? ? ? ?0.000 ? ? ? ? ?0.004 ? ? ? ? ? ? 0.0 ? ? ? ?
7 ? ? 500 ?10001 ?20210609 ?17 ? ? 0.000 ? ? ? ? 0.069 ? ? ? ? ? ? ?0.000 ? ? ? ? ?0.004 ? ? ? ? ? ? 0.0 ? ? ? ?
8 ? ? 500 ?10001 ?20210609 ?18 ? ? 0.000 ? ? ? ? 0.054 ? ? ? ? ? ? ?0.000 ? ? ? ? ?0.002 ? ? ? ? ? ? 0.0 ? ? ? ?
9 ? ? 500 ?10001 ?20210609 ?19 ? ? 0.000 ? ? ? ? 0.054 ? ? ? ? ? ? ?0.000 ? ? ? ? ?0.002 ? ? ? ? ? ? 0.0 ? ? ? ?
10 ? ?500 ?10001 ?20210609 ?20 ? ? 0.000 ? ? ? ? 0.040 ? ? ? ? ? ? ?0.000 ? ? ? ? ?0.004 ? ? ? ? ? ? 0.0 ?
... ? ... ? ... ? ? ... ? ? ... ? ? ... ? ? ? ? ? ... ? ? ? ? ? ? ? ?... ? ? ? ? ? ?... ? ? ? ? ? ? ?...
... ? ... ? ... ? ? ... ? ? ... ? ? ... ? ? ? ? ? ... ? ? ? ? ? ? ? ?... ? ? ? ? ? ?... ? ? ? ? ? ? ?...
... ? ... ? ... ? ? ... ? ? ... ? ? ... ? ? ? ? ? ... ? ? ? ? ? ? ? ?... ? ? ? ? ? ?... ? ? ? ? ? ? ?...
239 ? 500 ?10001 ?20210609 ?23 ? ? 0.000 ? ? ? ? 0.040 ? ? ? ? ? ? ?0.000 ? ? ? ? ?0.004 ? ? ? ? ? ? 0.0 ? ??
查看數據框td_link_data中數據類型df.dtypes:
print(td_link_data.dtypes)
結果:?
鏈路ID ? ? ? ? ? ?int64
管理域 ? ? ? ? ? ? int64
日期 ? ? ? ? ? ? object
時間 ? ? ? ? ? ? object
上行速率Mbps ? ? ?float64
上行對比速率Mbps ? ?float64
下行速率Mbps ? ? ?float64
下行對比速率Mbps ? ?float64
上行丟棄速率Mbps ? ?float64
dtype: object
2.維度查看df.shape:
print(td_link_data.shape)
?結果:?說明此數據框一共有240行,9列:
?(240, 9)
3.數據框的策略基本信息df.info():
維度、列名稱、數據格式、所占空間等
print(td_link_data.info())
結果:
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 240 entries, 0 to 239
Data columns (total 9 columns):
?# ? Column ? ? ?Non-Null Count ?Dtype ?
--- ?------ ? ? ?-------------- ?----- ?
?0 ? 鏈路ID ? ? ? ?240 non-null ? ?int64 ?
?1 ? 管理域 ? ? ? ? 240 non-null ? ?int64 ?
?2 ? 日期 ? ? ? ? ?240 non-null ? ?object?
?3 ? 時間 ? ? ? ? ?240 non-null ? ?object?
?4 ? 上行速率Mbps ? ?240 non-null ? ?float64
?5 ? 上行對比速率Mbps ?240 non-null ? ?float64
?6 ? 下行速率Mbps ? ?240 non-null ? ?float64
?7 ? 下行對比速率Mbps ?240 non-null ? ?float64
?8 ? 上行丟棄速率Mbps ?240 non-null ? ?float64
dtypes: float64(5), int64(2), object(2)
memory usage: 17.0+ KB
解釋:
1.數據類型:數據框 <class 'pandas.core.frame.DataFrame'>
2.表格的維度:240行x9列,RangeIndex:0-239
3.表格的列名,是否為空值和列字段類型dtype
4.數據框包含的字段類型及數量: float64(5), int64(2), object(2)
5.表格所占空間:17.0+ KB
4.某一列格式df['列名'].dtype:
print(td_link_data['管理域'].dtype)
結果:
?int64
需要強調的是object類型實際上可以包括多種不同的類型,比如一列數據里,既有整型、浮點型,也有字符串類型,這些在pandas中都會被標識為‘object’,所以在處理數據時,可能需要額外的一些方法提前將這些字段做清洗,str.replace(),float(),int(),astype(),apply()等等。
5.數據類型轉換.astype:
df.index.astype('int64') # 索引類型轉換
df.astype('int64') # 所有數據轉換為 int64
df.astype('int64', copy=False) # 不與原數據關聯
td_link_data.astype({'管理域': 'int32'}) # 指定字段轉指定類型
td_link_data['管理域'].astype('float') #某一列轉換
td_link_data['鏈路ID'].astype('object') #某一列轉換
參考鏈接:https://www.jianshu.com/p/8a5f0710cad3
原文鏈接:https://blog.csdn.net/weixin_44214830/article/details/117773082
相關推薦
- 2022-04-11 shell腳本根據進程查找指定容器的方法_linux shell
- 2022-11-29 C#泛型的使用案例_C#教程
- 2022-03-23 C語言?scanf的工作原理詳解_C 語言
- 2022-11-01 Python正則表達中re模塊的使用_python
- 2022-06-24 python文件讀取和導包的絕對路徑、相對路徑詳解_python
- 2023-03-16 redis刪除hash的實現方式_Redis
- 2022-05-31 python字典中get()函數的基本用法實例_python
- 2022-07-02 C語言詳細講解指針數組的用法_C 語言
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支