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 ...
随机推荐
- chrome headless
最近才知道有这么个东西,说白了就是chrome浏览器的命令行模式,一说到命令行自然就和自动化 高效率有关系,感觉对于自动化测试和爬虫很有用啊
- Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 at ExTestDrive.main ...
- 《Effective Java》第8章 通用程序设计
第47条:了解和使用类库 Top 100 Java Libraries on Github 2016 Library Number of Projects Type % of projects jun ...
- 按失真类型分类整理IQA数据集:TID2013
前面已经整理了TID2008,这次整理TID2013的工作相对较简单,只需要改代码的一部分就可以了,首先我大概介绍一些TID2013. TID2013是TID2008的加强版,链接如下:http:// ...
- java多线程系列:通过对战游戏学习CyclicBarrier
CyclicBarrier是java.util.concurrent包下面的一个工具类,字面意思是可循环使用(Cyclic)的屏障(Barrier),通过它可以实现让一组线程到达一个屏障(也可以叫同步 ...
- FineUI从iis6迁移到iis7.5上遇到的奇葩事情
前天把一台旧服务器上的windows2003+iis6上的fineui项目迁移到了win7+iis7上面来了,没有编译,直接以源码方式运行. 本来运行的好好的,昨天下午在上面用vs2010打开了一下看 ...
- 哈雷监控设备的操作及升级NSG9k6G
哈雷监控设备的操作及升级NSG9k6G 一.下载升级包: http://pan.baidu.com/s/1kTmw9sr 如连接不可以用可以直接私聊我.QQ1841031740 二.升级: 下载完后, ...
- 改变HTML文件上传控件样式
思路: 1.重写一个新的样式 2.将默认样式设置display:none;,即设为不可见 3.在js里调用:当点击新样式的时候,调用这个input的点击事件 html: <div class=& ...
- Alyona and towers CodeForces - 739C (线段树)
大意: 给定序列, 要求实现区间加, 询问整个序列最长的先增后减的区间. 线段树维护左右两端递增,递减,先增后减的长度即可, 要注意严格递增, 合并时要注意相等的情况, 要注意相加会爆int. #in ...
- loj#6040. 「雅礼集训 2017 Day5」矩阵(线性代数+递推)
题面 传送门 题解 我的线代学得跟屎一样看题解跟看天书一样所以不要指望这题我会写题解 这里 //minamoto #include<bits/stdc++.h> #define R reg ...