python dict to dataframe
http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.from_dict.html
Examples
By default the keys of the dict become the DataFrame columns:
>>> 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
Specify orient='index'
to create the DataFrame using dictionary keys as rows:
>>> 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
When using the ‘index’ orientation, the column names can be specified manually:
>>> 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
python dict to dataframe的更多相关文章
- Python dict operation introduce
字典是另一种可变容器模型,且可存储任意类型对象. 字典的每个键值(key=>value)对用冒号(:)分割,每个对之间用逗号(,)分割,整个字典包括在花括号({})中 ,格式如下所示: d = ...
- Python dict(或对象)与json之间的互相转化
Python dict(或对象)与json之间的互相转化 原文转载自 1.JSON:JavaScript 对象表示法,是轻量级的文本数据交换格式,独立于语言,平台 2.JSON 语法规则 数据在名称/ ...
- python. pandas(series,dataframe,index) method test
python. pandas(series,dataframe,index,reindex,csv file read and write) method test import pandas as ...
- python & dict & switch
python & dict & switch python 中是没用switch语句的,这应该是体现python大道至简的思想,python中一般多用字典来代替switch来实现. # ...
- Python dict() 函数
Python dict() 函数 Python 内置函数 描述 dict() 函数用于创建一个字典. 语法 dict 语法: class dict(**kwarg) class dict(mappi ...
- python dict乱码如何解决
定义字典并直接输出,结果输出结果中文是乱码展示 d={'name':'lily','age':18,'sex':'女','no':1121} print d 输出结果: {'age': 18, 'no ...
- python基础:如何使用python pandas将DataFrame转换为dict
之前在知乎上看到有网友提问,如何将DataFrame转换为dict,专门研究了一下,pandas在0.21.0版本中是提供了这个方法的.下面一起学习一下,通过调用help方法,该方法只需传入一个参数, ...
- Python array,list,dataframe索引切片操作 2016年07月19日——智浪文档
array,list,dataframe索引切片操作 2016年07月19日——智浪文档 list,一维,二维array,datafrme,loc.iloc.ix的简单探讨 Numpy数组的索引和切片 ...
- 转:python dict按照value 排序
我们知道Python的内置dictionary数据类型是无序的,通过key来获取对应的value.可是有时我们需要对dictionary中 的item进行排序输出,可能根据key,也可能根据value ...
随机推荐
- java的lamda表达式
Java8才支持lamda表达式 lamda是一中函数式编程语言 通过实现模式是匿名内部类 java使用内部类实现接口 首先定义一个接口 @FunctionalInterfaceinterface ...
- Mysql 5.7--ubuntu18.04 安装过程及遇到的问题
Mysql 5.7安装过程 1. 下载mysql的apt-config文件 a. https://dev.mysql.com/downloads/file/?id=477124 b. 点击downlo ...
- 重新使用linux的一些事情
workstatin版基本上已经有了常用的那些功能了, 代码开发完全足够了, 不需要再去加什么东东了 httpd已经有了, 结构: /usr/lib: 库,放置的是 (操作)系统的静态库, 大多数是直 ...
- Xgboost GPU 加速
import xgboost as xgb import numpy as np from sklearn.datasets import fetch_covtype from sklearn.mod ...
- 打包发布Python模块或程序,安装包
Python模块.扩展和应用程序可以按以下几种形式进行打包和发布: python setup.py获取帮助的方式 python setup.py --help python setup.py --he ...
- HTTP请求8种方法
HTTP/1.1协议中定义了八种方法(有时也叫“动作”)来表明Request-URI指定的资源的不同操作方式: OPTIONS 返回服务器针对特定资源所支持的HTTP请求方法.也可以利用向Web服务器 ...
- webpack dllPlugin使用(基于vue-cli webpack模板)
由于本例单入口时打包的文件体积过大,将其分成多入口. 主要涉及到的几个文件为: /index.html, /webpack.dll.config.js, /build/webpack.base.con ...
- UVALive - 5857 Captain Q's Treasure
UVALive - 5857 思路: 状压dp,用map写 代码: #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimi ...
- 《javascript经典入门》-day01
<javascript经典入门>-day01 1.了解JavaScript 01.浏览器每次加载和显示页面时,都在内存里创建页面及其全部元素的一个内部表示体系,,也就是DOM.在DOM里, ...
- Lab 10-3
This lab includes a driver and an executable. You can run the executable from anywhere, but in order ...