Possible data inputs to DataFrame constructor
Possible data inputs to DataFrame constructor:
import pandas as pd
import numpy as np
(1) 2D ndarray
pd.DataFrame(np.arange(12).reshape(3,4))
| 0 | 1 | 2 | 3 | |
|---|---|---|---|---|
| 0 | 0 | 1 | 2 | 3 |
| 1 | 4 | 5 | 6 | 7 |
| 2 | 8 | 9 | 10 | 11 |
(2)dict of arrays,lists,tuples or series
pd.DataFrame({'a':[1,2,3],'b':[2,3,4],'c':[4,5,6]})
| a | b | c | |
|---|---|---|---|
| 0 | 1 | 2 | 4 |
| 1 | 2 | 3 | 5 |
| 2 | 3 | 4 | 6 |
pd.DataFrame({'a':np.array([1,2,3]),'b':np.array([2,3,4]),'c':np.arange(3)})
| a | b | c | |
|---|---|---|---|
| 0 | 1 | 2 | 0 |
| 1 | 2 | 3 | 1 |
| 2 | 3 | 4 | 2 |
a=pd.Series([1,2,3]);b=pd.Series([2,3,4]);c=pd.Series([0,1,2])
pd.DataFrame({'a':a,'b':b,'c':c})
| a | b | c | |
|---|---|---|---|
| 0 | 1 | 2 | 0 |
| 1 | 2 | 3 | 1 |
| 2 | 3 | 4 | 2 |
(3)dict of dicts
pd.DataFrame({'a':{0:1,1:2,2:3},'b':{0:2,1:3,2:3},'c':{0:0,1:1,2:2}})
| a | b | c | |
|---|---|---|---|
| 0 | 1 | 2 | 0 |
| 1 | 2 | 3 | 1 |
| 2 | 3 | 3 | 2 |
(4)list of lists or tuples
a=pd.DataFrame([[1,2,3],[2,3,4],[0,1,2]],index=['aa','bb','cc'],columns=['a','b','c']);a
| a | b | c | |
|---|---|---|---|
| aa | 1 | 2 | 3 |
| bb | 2 | 3 | 4 |
| cc | 0 | 1 | 2 |
(5)another DataFrame's values
pd.DataFrame(a.values,index=['naa','nbb','ncc'],columns=['na','nb','nc']) #Note that,using a.values
| na | nb | nc | |
|---|---|---|---|
| naa | 1 | 2 | 3 |
| nbb | 2 | 3 | 4 |
| ncc | 0 | 1 | 2 |
Possible data inputs to DataFrame constructor的更多相关文章
- R 给data.frame(dataframe)添加一列
x<-data.frame(apple=c(1,4,2,3),pear=c(4,8,5,2)) x # apple pear # 1 1 4 # 2 4 8 # 3 2 5 # 4 3 2 x$ ...
- org.springframework.data.mongodb.core.MongoTemplate]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError: org.springframework.core.convert.support.ConversionServiceFactory.cr
spring-data-mongo 和spring core包冲突.解决办法: <dependency> <groupId>org.springframework.data&l ...
- Pandas 之 Series / DataFrame 初识
import numpy as np import pandas as pd Pandas will be a major tool of interest throughout(贯穿) much o ...
- Python pandas 0.19.1 Intro to Data Structures 数据结构介绍 文档翻译
官方文档链接http://pandas.pydata.org/pandas-docs/stable/dsintro.html 数据结构介绍 我们将以一个快速的.非全面的pandas的基础数据结构概述来 ...
- 数据分析---《Python for Data Analysis》学习笔记【04】
<Python for Data Analysis>一书由Wes Mckinney所著,中文译名是<利用Python进行数据分析>.这里记录一下学习过程,其中有些方法和书中不同 ...
- Coursera, Big Data 3, Integration and Processing (week 5)
Week 5, Big Data Analytics using Spark Programing in Spark Spark Core: Programming in Spark us ...
- DataFrame对行列的基本操作实战
1.pandas对行列的基本操作命令: import numpy as np import pandas as pd from pandas import Sereis, DataFrame ser ...
- 02. Pandas 1|数据结构Series、Dataframe
1."一维数组"Series Pandas数据结构Series:基本概念及创建 s.index . s.values # Series 数据结构 # Series 是带有标签的一 ...
- [转]python中pandas库中DataFrame对行和列的操作使用方法
转自:http://blog.csdn.net/u011089523/article/details/60341016 用pandas中的DataFrame时选取行或列: import numpy a ...
- How to use Data Iterator in TensorFlow
How to use Data Iterator in TensorFlow one_shot_iterator initializable iterator reinitializable iter ...
随机推荐
- 用 solon-ai 写个简单的 deepseek 程序(构建全国产 ai 智能体应用)
用国产应用开发框架(及生态),对接国产 ai.构建全国产 ai 智能体应用. 1.先要申请个 apiKey 打开 https://www.deepseek.com 官网,申请个 apiKey .(一万 ...
- go map fatal error: concurrent map iteration and map write 读写锁与深度拷贝的坑
起因 从币安实时拉取交易对的数据,这里使用了 map,用于存放每个交易对的最新价格,由于 map 并不是并发安全的所以加了读写锁. 但系统有时候还是会发生 fatal error: concurren ...
- godoc使用方法介绍
一.go doc简介 Godoc是go语言的文档化工具,类似于文档化工具godoc,类似于Python的Docstring和Java的Javadoc Godoc通过解析包含注释的Go代码来生成HTML ...
- postman发送数组
postman发送数组 第一种 第二种
- Linux 防火墙及开放端口管理
查看防火墙是否开启systemctl status firewalld 若没有开启则是开启状态systemctl start firewalld 关闭则start改为stop 查看所有开启的端口fi ...
- StarRocks 升级注意事项
前段时间升级了生产环境的 StarRocks,从 3.3.3 升级到了 3.3.9,期间还是踩了不少坑所以在这里记录下. 因为我们的集群使用的是存算分离的版本,也是使用官方提供的 operator 部 ...
- 基础命令:dd、tar、ln、find、逻辑符号、alisa别名、md5sun校验、lrzsz文件上传下载、wget
目录 3.0 dd读取.转换并输出数据 3.1 压缩 (tar.zip).解压缩(tar xf.unzip) 3.2 ln软硬链接 3.2.1 软链接: 3.2.2 硬链接: 3.3 find文件查找 ...
- Ubuntu截屏工具推荐
Ubuntu截屏工具推荐 本篇博文推荐Ubuntu下的截屏工具Flameshot,可以作为Windows下Snipaste截图工具的平替. GitHub地址:https://github.com/fl ...
- 【Java】异常处理
异常的定义 异常:在Java语言中,将程序执行中发生的不正常情况称为"异常". (开发过程中的语法错误和逻辑错误不是异常) 1. 异常的体系结构 Java程序在执行过程中所发生的异 ...
- xe下ro流导致的错误
server端ro7.0的版本,client用的Xe10.3下Ro9.0.导致clientdataset数据记录有几十条就会出现内存泄漏现象.根源在下面: Remobjects9.0与XE10.3自带 ...