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 ...
随机推荐
- Flink - [03] API
使用scala编写flink api从不同的数据源(源端)读取数据,并进行无界流/有界流的数据处理,最终将处理好的数据sink到对应的目标端 一.maven配置 <?xml version=&q ...
- MySQL - [09] 正则表达式
转载:https://mp.weixin.qq.com/s/7RavuYGs9SthX2pxGJppqw select * from t1 where name rlike '^[a-zA-Z]+$' ...
- Elasticsearch搜索引擎学习笔记(三)
索引的一些操作 集群健康 GET /_cluster/health 创建索引 PUT /index_test { "settings": { "index": ...
- nnUNet 使用方法
首先明确分割任务. 其次明确研究方法和步骤. 再做好前期准备,如数据集的采集.标注以及其中的训练集/测试集划分. 其中的参考链接: (四:2020.07.28)nnUNet最舒服的训练教程(让我的奶奶 ...
- How to use the shell, terminal and the advanced tools
How to use the shell, terminal and the advanced tools Introduction Why use English instead of Chin ...
- 大模型基础补全计划(二)---词嵌入(word embedding)
PS:要转载请注明出处,本人版权所有. PS: 这个只是基于<我自己>的理解, 如果和你的原则及想法相冲突,请谅解,勿喷. 环境说明 无 前言 本文是这个系列第二篇,它们是: &l ...
- gorm stdErr = sql: Scan error on column index 0, name "total": converting NULL to float64 is unsupported
前言 使用 gorm 查询时,报错:stdErr = sql: Scan error on column index 0, name "total": converting NUL ...
- 解决PyCharm提示Error: Please select a valid Python interpreter
前言 Pycharm运行Python3.7.8的程序时发现源程序运行报错(非语法错误) Error:please select a valid Python interpreter 解决 第一步:打开 ...
- Xshell连接VirtualBox虚拟机中的CentOS
前提: 安装好VirtualBox虚拟机,并且在虚拟机上安装好CentOS系统. 具体步骤: 1.进入CentOS虚拟机设置--网络--高级--端口转发 2.新增端口规则,按照下面图片填写. 3.打开 ...
- vue学习一(指令1.v-text,v-html,插值表达式{{msg}})
一.1.v-text,v-html,插值表达式{{msg}} 注:v-text解决差值表达式闪烁问题,因为他是属性不是差值表达式 1.1.v-text: 是没有闪烁问题的,会覆盖标签的元素中原本的内容 ...