python. pandas(series,dataframe,index,reindex,csv file read and write) method test
import pandas as pd
import numpy as np
def testpandas():
p = pd.Series([1,2,3,4,5],index =('a','b','c','d','e'))
print(p) cities = {'bejing':5500,'shanghai':5999,'shezhen':6000,'suzhou':None}
p2 = pd.Series(cities,name ='prices')
print(p2[:-1])
print('bejing' in p2)
print(p2.get('bejing'))
print(p2[p2 < 6000])
print(p.mean())
s = pd.Series(np.random.randn(5),index =[1,2,3,4,5])
print(np.random.randn(5)) le = p2 < 5600
print(le)
print(p2[le])
print('---------------------------')
p2['bejing']=7000
print(p2/2)
print(np.log(p2))
print('---------------------------')
com=p + p2
print(com)
print('---------------------------') data={'city':['bj','shenzhen','shanhai'],
'year':[2011,2013,2014],
'pop':[2100,2200,2430]}
df = pd.DataFrame(data,columns=['year','city','pop'],index=['one','two','three'])
print(df)
print('---------------------------')
df2=pd.DataFrame({'city':p2,'p1':p})
print(df2)
print('---------------------------') data2=[{'july':9999,'han':5000,'zewei':1000},{'july':9999,'han':5000,'zewei':1000},{'july':9999,'han':5000,'zewe2i':1000}]
df3=pd.DataFrame(data2)
print(df3)
print(df3.loc[[1,2]])
print(df3['han'])
print('---------------------------')
print(df3.iloc[0:2])
print('---------------------------')
df3.loc[1]=9000
df3['han']=9000
print(df3)
print(df3.shape[1])
print(df3.columns)
print('---------------------------')
print(df3.info())
df3.index.name='city'
df3.columns.name='info'
print('---------------------------')
print(df3)
row =df3.loc[0]
print(row) print(df3.sub(row,axis=1))
print('---------------------------')
col=df3['july']
print(col)
print(df3.sub(col,axis=0))
print('---------------------------')
index=pd.Index(['shanghai','guangzhou','shenzheng'])
print(index)
obj = pd.Series(range(3),index=['a','b','c'])
obj_index=obj.index
print(obj_index[1:]) print(df3.drop([0,1]))
print(df3) print(df3)

#read and write csv of pandas
goog =pd.read_csv(r'C:\python\demo\LiaoXueFeng\data\test_vrt.csv',index_col=0)
goog=goog.reindex(pd.to_datetime(goog.index))
print(goog.head())
print(goog.tail())
data2 = [{'july': 9999, 'han': 5000, 'zewei': 1000}, {'july': 9999, 'han': 5000, 'zewei': 1000},
{'july': 9999, 'han': 5000, 'zewe2i': 1000}]
df3 = pd.DataFrame(data2)
df3.to_csv(r'C:\python\demo\LiaoXueFeng\data\goog2.csv',encoding='GBK',mode='a')

python. pandas(series,dataframe,index) method test的更多相关文章

  1. python pandas.Series&&DataFrame&& set_index&reset_index

    参考CookBook :http://pandas.pydata.org/pandas-docs/stable/cookbook.html Pandas set_index&reset_ind ...

  2. python pandas ---Series,DataFrame 创建方法,操作运算操作(赋值,sort,get,del,pop,insert,+,-,*,/)

    pandas 是基于 Numpy 构建的含有更高级数据结构和工具的数据分析包 pandas 也是围绕着 Series 和 DataFrame 两个核心数据结构展开的, 导入如下: from panda ...

  3. Python Pandas -- Series

    pandas.Series class pandas.Series(data=None, index=None, dtype=None, name=None, copy=False, fastpath ...

  4. python基础:如何使用python pandas将DataFrame转换为dict

    之前在知乎上看到有网友提问,如何将DataFrame转换为dict,专门研究了一下,pandas在0.21.0版本中是提供了这个方法的.下面一起学习一下,通过调用help方法,该方法只需传入一个参数, ...

  5. Pandas数据结构(一)——Pandas Series

    Pandas 是 Python 中基于Numpy构建的数据操纵和分析软件包,包含使数据分析工作变得快速简洁的高级数据结构和操作工具.通过Pandas Series 和 Pandas DataFrame ...

  6. pandas.Series

    1.系列(Series)是能够保存任何类型的数据(整数,字符串,浮点数,Python对象等)的一维标记数组.轴标签统称为索引. Pandas系列可以使用以下构造函数创建 - pandas.Series ...

  7. pandas数据结构:Series/DataFrame;python函数:range/arange

    1. Series Series 是一个类数组的数据结构,同时带有标签(lable)或者说索引(index). 1.1 下边生成一个最简单的Series对象,因为没有给Series指定索引,所以此时会 ...

  8. 利用Python进行数据分析:【Pandas】(Series+DataFrame)

    一.pandas简单介绍 1.pandas是一个强大的Python数据分析的工具包.2.pandas是基于NumPy构建的.3.pandas的主要功能 --具备对其功能的数据结构DataFrame.S ...

  9. Pandas 之 Series / DataFrame 初识

    import numpy as np import pandas as pd Pandas will be a major tool of interest throughout(贯穿) much o ...

随机推荐

  1. MongoDB 学习笔记(9)--- Limit与Skip方法

    MongoDB Limit() 方法 如果你需要在MongoDB中读取指定数量的数据记录,可以使用MongoDB的Limit方法,limit()方法接受一个数字参数,该参数指定从MongoDB中读取的 ...

  2. css中position:fixed实现div居中

    上下左右 居中 代码如下 复制代码 div{ position:fixed; margin:auto; left:0; right:0; top:0; bottom:0; width:200px; h ...

  3. dpkg卸载deb包

    一.背景: 一个脚本安装mysql,结果提示缺少依赖库,安装失败. 二.查询: 此时查询deb文件已经安装的情况,得到这个结果: root@debian:~# dpkg -l |grep mysql- ...

  4. C#winform实现跑马灯

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  5. java中基础数据类型的应用

    1.float 与 double float是单精度类型,占用4个字节的存储空间  double是双精度类型,占用8个字节的存储空间  1)当你不声明的时候,默认小数都用double来表示,所以如果要 ...

  6. jenkins执行shell命令提示找不到命令解决办法

    用jenkins执行shell脚本,执行一条命令: #唤醒休眠手机 adb shell input keyevent 提示: [adb] $ /bin/sh -xe /Users/xxxxx/tool ...

  7. 在 Mac 上使用多点触控手势

    使用多点触控触控板或妙控鼠标,可以通过轻点.轻扫.捏合或开合一根或多根手指进行有用的操作. 触控板手势 有关这些手势的更多信息,请选取苹果菜单 () >“系统偏好设置”,然后点按“触控板”.您 ...

  8. Navicat_Premium 连接oracle遇到ORA-28457

    解决方案很简单,我用oracle文件目录下的oci.dll替换了navicat文件目录下的oci.dll,之后很顺畅地就连上了.

  9. django -- 联合索引

    一.定义: from django.db import models # Create your models here. class Person(models.Model): first_name ...

  10. RabbitMQ 消费端 Client CPU 100%的解决办法

    Func<bool> run = () => { try { using (IConnection conn = cf.CreateConnection()) { using (IM ...