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_clipboard
1. 先来个小菜
基于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 ...
随机推荐
- 为什么不推荐用破解版的winrar
站在winrar公司的角度,作为winrar的开发商或者运营商当然不希望用户使用破解版的winrar,因为这损害了他们的利益,这是屁股问题. 站在用户的角度,我希望免费使用世界上所有的软件.但这个世界 ...
- Linux kdb命令
一.简介 Linux 内核调试器(KDB)允许您调试 Linux 内核.这个恰如其名的工具实质上是内核代码的补丁,它允许高手访问内核内存和数据结构.KDB 的主要优点之一就是它不需要用另一台机器进行调 ...
- GCD 学习(一)简介
文章摘抄至:http://zhuyanfeng.com/archives/3015 并有一些改动 GCD(Grand Central Dispatch)是从OS X Snow Leopard和iOS ...
- p2234&bzoj1588 营业额统计
传送门 题目 营业额统计 Tiger最近被公司升任为营业部经理,他上任后接受公司交给的第一项任务便是统计并分析公司成立以来的营业情况. Tiger拿出了公司的账本,账本上记录了公司成立以来每天的营业额 ...
- CF1063B Labyrinth
大家一起膜Rorshach. 一般的$bfs$会造成有一些点访问不到的情况,在$system\ test$的时候会$WA40$(比如我……). 发现这张地图其实是一个边权只有$0/1$的图,我们需要计 ...
- 解决.jsp及静态资源文件访问404的问题
我们在做Web项目时,经常将.jsp文件放到webapp\WEB-INF下,这时,我们访问jsp等文件的时候,就会报404. 如果是纯前后端分离的项目,后端只返回数据,不处理页面,也没问题.但,有时我 ...
- 【IMOOC学习笔记】多种多样的App主界面Tab实现方法(一)
1.ViewPager实现Tab 首先实现底部和底部布局 <?xml version="1.0" encoding="utf-8"?> <Li ...
- c++内联 inline
内联声明只是建议 ,不一定就会内联. http://www.voidcn.com/blog/u011327981/article/p-5006835.html
- 写RestApi需要注意些什么?
PS1="\n[\e[32;1m]([\e[37;1m]\u[\e[32;1m])-([\e[37;1m]jobs:\j[\e[32;1m])-([\e[37;1m]\w[\e[32;1m] ...
- Pandas——读取csv,txt文件
""" 读取csv文件 该文本中的分割符既有空格又有制表符(‘/t’),sep参数用‘/s+’,可以匹配任何空格. """ import p ...