美文网首页Pandas
Python 数据分析

Python 数据分析

作者: Liam_ml | 来源:发表于2019-01-04 10:46 被阅读4次

数据结构

pandas是数据分析的模块,其主要的数据结构是SeriesDataFrame

创建

创建一个Series直接传入一个列表:o = pandas.Series([1,2,3,4],index=['a','b','c','d'])

取子集可以使用位置也可以使用索引值:


o
Out[28]: 
a    1
b    2
c    3
d    4
f    5
dtype: int64

o[1]
Out[29]: 2

o['a']
Out[30]: 1

数据框是从R语言里面延伸过来的,创建DataFrame 的方式有很多:

  • 二维ndarray
  • 字典
  • Series组成的字典
  • 字典或Series的列表

丢弃不需要的列:

o.drop

进行索引

data = pandas.DataFrame(numpy.arange(16).reshape(4,4),index = ['Ohio','co','Ut','N Y'],columns = ['one','two','three','four'])

可以通过列名索引

data['one']

data[['one','two']]


也可以通过位置索引,行

 data[:2]
 
 
需要通过ix索引列

data.ix[1,1]

data.ix[0,0]

data.ix[0:3,0:3]

如何获取帮助

  • help
  • dir

相关文章

网友评论

    本文标题:Python 数据分析

    本文链接:https://www.haomeiwen.com/subject/mbqhrqtx.html