Python Pandas -- DataFrame
pandas.DataFrame
- class
pandas.DataFrame(data=None, index=None, columns=None, dtype=None, copy=False)[source] -
Two-dimensional size-mutable, potentially heterogeneous tabular data structure with labeled axes (rows and columns). Arithmetic operations align on both row and column labels. Can be thought of as a dict-like container for Series objects. The primary pandas data structure
Parameters: data : numpy ndarray (structured or homogeneous), dict, or DataFrame
Dict can contain Series, arrays, constants, or list-like objects
index : Index or array-like
Index to use for resulting frame. Will default to np.arange(n) if no indexing information part of input data and no index provided
columns : Index or array-like
Column labels to use for resulting frame. Will default to np.arange(n) if no column labels are provided
dtype : dtype, default None
Data type to force. Only a single dtype is allowed. If None, infer
copy : boolean, default False
Copy data from inputs. Only affects DataFrame / 2d ndarray input
See also
DataFrame.from_records- constructor from tuples, also record arrays
DataFrame.from_dict- from dicts of Series, arrays, or dicts
DataFrame.from_items- from sequence of (key, value) pairs
pandas.read_csv,pandas.read_table,pandas.read_clipboard1. 先来个小菜
基于dictionary创建
from pandas import Series, DataFrame
import pandas as pd
import numpy as np
d = {'col1':[1,2],'col2':[3,4]}
df = pd.DataFrame(data=d)
print(df)
print(df.dtypes)
# col1 col2
#0 1 3
#1 2 4
#col1 int64
#col2 int64
#dtype: object基于Numy的ndarrary
df2 = pd.DataFrame(np.random.randint(low=0, high=10, size=(5, 5)),columns=['a', 'b', 'c', 'd', 'e'])
print (df2)
# a b c d e
#0 0 2 4 7 0
#1 6 7 3 4 1
#2 5 3 3 8 7
#3 0 9 4 3 4
#4 7 4 7 0 0
Python Pandas -- DataFrame的更多相关文章
- Python pandas DataFrame操作
1. 从字典创建Dataframe >>> import pandas as pd >>> dict1 = {'col1':[1,2,5,7],'col2':['a ...
- Python pandas.DataFrame调整列顺序及修改index名
1. 从字典创建DataFrame >>> import pandas >>> dict_a = {'],'mark_date':['2017-03-07','20 ...
- python pandas.DataFrame选取、修改数据最好用.loc,.iloc,.ix
先手工生出一个数据框吧 import numpy as np import pandas as pd df = pd.DataFrame(np.arange(0,60,2).reshape(10,3) ...
- python pandas dataframe to_sql方法error及其解决
今天遇到了一个问题,很是奇怪,自己也想了一个另类的方法将其解决了,现在将详细过程经过记录如下: 我在处理完一个dataframe之后,需要将其写回到数据库.这个dataframe比较大,共有53列,7 ...
- python pandas.DataFrame.append
1.使用append首先要注意的是,你要合并两个DataFrame的columns即列名是否是相同的,不相同的就会报错. 2.我们会发现DataFrame的列名是不能够重复的,而行名(index)是可 ...
- python pandas dataframe 操作记录
从数据看select出数据后如何转换为dataframe df = DataFrame(cur.fetchall()) 如何更改列名,选取列,进行groupby操作 df.columns = ['me ...
- python pandas.DataFrame .loc,.iloc,.ix 用法
refer to: http://www.cnblogs.com/harvey888/p/6006200.html
- python pandas dataframe 读取和写入Oracle
1.代码:主要写入时表要为小写,否则报错 Could not reflect: requested table(s) not available in Engine from sqlalchemy i ...
- python pandas.Series&&DataFrame&& set_index&reset_index
参考CookBook :http://pandas.pydata.org/pandas-docs/stable/cookbook.html Pandas set_index&reset_ind ...
随机推荐
- 杭电ACM刷题(1):1002,A + B Problem II 标签: acmc语言 2017-05-07 15:35 139人阅读 评
最近忙于考试复习,没有多少可供自己安排的时间,所以我利用复习之余的空闲时间去刷刷杭电acm的题目,也当对自己编程能力的锻炼吧. Problem Description I have a very si ...
- SQLServer存储引擎——03.日志
3. SQLServer存储引擎之日志篇 (3.1)日志结构 (3.1.1)物理日志 (0)物理日志即数据库的.ldf文件, 当然后缀名是可以自定义的,默认是.ldf (1)一个SqlServer数据 ...
- VB.NET提取TXT文档指定内容
今天有浏览论坛时,又看见一篇是读取TXT文本文件的论题.Insus.NET也想以自己的想法来实现,并分享于此. 文本文件是比较复杂,获取数据也是一些文本行中取其中一部分.为了能够取到较精准的数据,In ...
- 【bzoj2242】: [SDOI2011]计算器 数论-快速幂-扩展欧几里得-BSGS
[bzoj2242]: [SDOI2011]计算器 1.快速幂 2.扩展欧几里得(费马小定理) 3.BSGS /* http://www.cnblogs.com/karl07/ */ #include ...
- ThinkPHP3.2.3完整版创建前后台入口文件 http://jingyan.baidu.com/article/7e4409533fc1092fc1e2ef53.html
ThinkPHP3.2.3完整版创建前后台入口文件 1 2 3 4 5 6 7 分步阅读 ThinkPHP是为了简化企业级应用开发和敏捷WEB应用开发而诞生的优秀的国产php框架,值得我们去探索学 ...
- B君的第九题
B君的第九题 对于一个排列\(a_1, a_2,\dots,a_n\),如果对于一个i满足\(a_{i-1}<a_i>a_i+1\)则称i是一个极大值.我们认为\(a_0=a_{n+1}= ...
- jzoj4916. 【GDOI2017模拟12.9】完全背包问题 (背包+最短路)
题面 题解 考场上蠢了--这么简单的东西都想不到-- 首先排序加去重. 先来考虑一下,形如 \[a_1x_1+a_2x_2+...a_nx_n=w,a_1<a_2<...<a_n,x ...
- Python Flask模块
模块是一个包含响应文本的文件,其中包含占用位变量表示的动态部分,其具体值只在请求的上下文中才知道.使用真实值替换变量,再返回最终得到的响应字符串,这一过程称为渲染.为了渲染模块,Flask使用一个名为 ...
- sql_trace基本用法
sql_trace是oracle提供的一个非常好的跟踪工具,主要用来检查数据库的异常情况,通过跟踪数据库的活动,找到有问题的语句. 一.概述: SQL_TRACE是Oracle的一个非常强大的工 ...
- P3879 [TJOI2010]阅读理解
\(\color{#0066ff}{ 题目描述 }\) 英语老师留了N篇阅读理解作业,但是每篇英文短文都有很多生词需要查字典,为了节约时间,现在要做个统计,算一算某些生词都在哪几篇短文中出现过. \( ...