Github上Pandas,Numpy和 Scipy三个库中20个最常用的函数(1)
2018-03-23 20:49
585 查看
pandas
pandas.DataFrame data=None, index=None, columns=None, dtype=None, copy=False)
DataFrame是一个表格型的数据结构,它含有一组有序的列,每列可以是不同的值类型(数值、字符串、布尔值等)。DataFrame既有行索引也有列索引,它可以被看做由Series组成的字典(共用同一个索引)。
参数
- 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
import pandas as pd df = pd.DataFrame(data={'y':[1,2,3], 'score':[93.5,89.4,90.3], 'name':['Dirac','pauli','Bohr'], 'birthday':['1902-08-02','1963-02-01','1923-04-05']}) print(type(df)) print(df.dtypes) print(df) ```运行结果 <div class="se-preview-section-delimiter"></div>
birthday object
name object
score float64
y int64
dtype: object
birthday name score y
0 1902-08-02 Dirac 93.5 1
1 1963-02-01 pauli 89.4 2
2 1923-04-05 Bohr 90.3 3
“`
2)pd.read_csv(filename):从CSV文件导入数据
读取CSV(逗号分割)文件到DataFrame
也支持文件的部分导入和选择迭代
未完
birthday object name object score float64 y int64 dtype: object birthday name score y 0 1902-08-02 Dirac 93.5 1 1 1963-02-01 pauli 89.4 2 2 1923-04-05 Bohr 90.3 3
**pd.read_csv**(filename):从CSV文件导入数据
读取CSV(逗号分割)文件到DataFrame
也支持文件的部分导入和选择
pd.Series (data, index=index)是一种类似于一维数组的对象,它由一组数据(各种NumPy数据类型)以及一组与之相关的数据标签(即索引)组成。
这里,data指代许多不同的数据类型:
a Python dict
an ndarray
a Python list
a scalar value
In [2]: obj = Series([4, 7, -5, 3]) In [3]: obj Out[3]: 0 4 1 7 2 -5 3 3 dtype: int64
pd.concatt(objs, axis=0, join='outer', join_axes=None, ignore_index=False,keys=None, levels=None, names=None, verify_integrity=False)
参数说明
objs: series,dataframe或者是panel构成的序列lsit
axis: 需要合并链接的轴,0是行,1是列
join:连接的方式 inner,或者outer
pd.to_datetime
获取指定的时间和日期
将str和unicode转化为时间格式
import pandas as pd print(pd.to_datetime('2018/04/03',format='%Y/%m/%d')) #2018-04-03 00:00:00
pd.merge
pd.date_range
pd.read_table
pd.util.testing
pd.isnull
pd.DatatimeIndex
pd.Index
pd.read_excel
pd.notnull
pd.DataFrame.from_csv
pd.HDFStore
pd.DataFrame.from_records
pd.MultiIndex.from_tuples
Numpy
np.array
np.zeros
np.arange
np.sqrt
np.ones
np.sum
np.mean
np.linspace
np.asarray
np.ndarray
np.dot
np.exp
np.abs
np.where
np.empty
np.max
np.concatenate
np.log
np.sin
np.vstack
scipy
sp.stats
sp.sparse
sp.optimize
sp.io
sp.linalg
sp.interpolate
sp.special
sp.singal
sp.ndimage
sp.misc
sp.integrate
sp.sparse.linalg
sp.spatial.distance
sp.spatial
sp.io.loadmat
sp.sparse.csr_matrix
sp.org
sp.csr_matrix
sp.array
sp.issparse
相关文章推荐
- Github上Pandas,Numpy和 Scipy三个库中20个最常用的函数
- 常用 pandas 和 numpy 函数总结
- 深度学习中几个常用包的参考文档(NumPy,SciPy,Matplotlib,pandas等)
- Python拓展包:Numpy,pandas...常用函数
- numpy与pandas常用函数
- numpy学习笔记2-常用函数
- pandas常用函数之diff
- numpy 常用工具函数 —— np.bincount/np.average
- pandas数据处理常用函数demo之创建/行列操作/查看/文件操作
- pandas常用函数之date_range
- pandas 常用函数大全
- pandas 常用函数
- 熟悉 NumPy 常用函数
- Python pandas常用函数详解
- Win 7/10安装numpy、pandas、scipy和matplotlib
- python及常用库numpy、scipy、matplotlib安装与卸载-Windows环境
- pandas 常用函数
- pandas做数据分析(四):常用函数
- python 如何安装Numpy Scipy pandas等扩展库
- Python-Numpy常用函数总结