網站首頁 編程語言 正文
pandas函數中pandas.DataFrame.from_dict 直接從字典構建DataFrame 。
參數解析
DataFrame from_dict()方法用于將Dict轉換為DataFrame對象。 此方法接受以下參數。
- data: dict or array like object to create DataFrame.data :字典或類似數組的對象來創建DataFrame。
- orient: The orientation of the data. The allowed values are (‘columns’, ‘index’), default is the ‘columns’. ?orient :數據的方向。 允許值為(“列”,“索引”),默認值為“列”。 Specify orient='index' to create the DataFrame using dictionary keys as rows:。 當參數orient為index值時,會將字典的keys作為DataFrame的行。(默認是keys變為列)
- columns: a list of values to use as labels for the DataFrame when orientation is ‘index’. If it’s used with columns orientation, ValueError is raised. ? ? columns :當方向為“索引”時,用作DataFrame標簽的值的列表。 如果與列方向一起使用,則會引發ValueError 。
實例 ?
1)By default the keys of the dict become the DataFrame columns:
默認是將字典的keys作為列
data = {'col_1': [3, 2, 1, 0], 'col_2': ['a', 'b', 'c', 'd']}
pd.DataFrame.from_dict(data)
col_1 col_2
0 3 a
1 2 b
2 1 c
3 0 d
2) Specify orient='index' to create the DataFrame using dictionary keys as rows: 參數orient為index值時,會將字典的keys作為DataFrame的行
data = {'row_1': [3, 2, 1, 0], 'row_2': ['a', 'b', 'c', 'd']}
pd.DataFrame.from_dict(data, orient='index')
0 1 2 3
row_1 3 2 1 0
row_2 a b c d
3) orient為index值時, 可以手動命名列名
pd.DataFrame.from_dict(data, orient='index',
columns=['A', 'B', 'C', 'D'])
A B C D
row_1 3 2 1 0
row_2 a b c d
參考: pandas.DataFrame.from_dict — pandas 1.3.4 documentation
原文鏈接:https://blog.csdn.net/wangwangstone/article/details/121304120
相關推薦
- 2022-03-12 Nginx熱部署的實現_nginx
- 2022-07-10 el-table收集列表中被選中復選框數據信息
- 2022-03-14 windows環境搭建golang的gin框架簡易教程
- 2022-04-08 詳解RIFF和WAVE音頻文件格式_相關技巧
- 2023-02-15 PyQt5+PyQt5Designer的安裝步驟_python
- 2022-07-15 Python中列表索引?A[?:?2?]與A[?:?,?2]的區別說明_python
- 2022-09-16 Pandas缺失值刪除df.dropna()的使用_python
- 2023-04-04 numpy中的norm()函數求范數實例_python
- 最近更新
-
- 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同步修改后的遠程分支