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')
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
2012-07-25 IOS NSInvocation用法
2012-07-25 Objective-C 基础,类和对象,方法和消息,已声明的属性和存取方法,块对象,协议和范畴类,预定义类型和编码策略
2012-07-25 IOS Object C id,class,sel,bool
2012-07-25 IOS 使用NSKeyedArchiver类进行对象序列化和反序列化
2012-07-25 工作时总结的iphone面试题,笔试题
2012-07-25 ios基础面试题
2012-07-25 ios技术面试题