![](https://img-blog.csdnimg.cn/20201014180756923.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
pandas
Marina-ju
虽恼太迟,又庆幸终于找到了喜欢的事
展开
-
df.ix的用法
转自:https://blog.csdn.net/weixin_38070397/article/details/80431546转载 2019-01-13 16:01:03 · 11301 阅读 · 5 评论 -
pandas 数据通过index排序
e=pd.DataFrame(b,index=a)e011 one010 one112 one26 one316 one413 one515 one68 ADL5 CEL9 CES7 up0 dn14 os4 price2 vol3 low1 hi...转载 2019-02-15 14:36:37 · 8605 阅读 · 0 评论 -
OneHotEncoder的理解
编码的对象是数组,编码逻辑是将行认为是sample,列认为是feature。将每列出现的值按一定的规律排列(比如大小),加入fit的数据又N列,encoder后的categories便会有N个。对于需要transform的数组来说,第一列中的值在categories的相应位置存在的,则为1,不存在,则为0 。以此类推,第N列中的值在第N个categories中存在就为1,不存在就为0。将所有 ...原创 2019-02-16 18:16:43 · 5064 阅读 · 0 评论 -
pd resample方法有groupby的作用
rng=pd.date_range(‘2000-01-01’,periods=100,freq=‘D’)ts=pd.DataFrame(np.random.randn(len(rng)),index=rng)ts.resample(‘M’).mean()02000-01-31 0.0888152000-02-29 -0.1145232000-03-31 -0.11204220...转载 2019-03-04 21:52:44 · 1094 阅读 · 0 评论 -
通用时间转换方式:parse
用法如下:from dateutil.parser import parseparse(‘20190101’)datetime.datetime(2019, 1, 1, 0, 0)较datetime.strptime()广泛,但是传入的数据不合法的话会被转为错误的时间格式...原创 2019-03-06 10:16:54 · 863 阅读 · 0 评论 -
pandas中的分类展示
dim=pd.Series([‘apple’,‘orange’])values=pd.Series([0,1]*4)dim.take(values)0 apple1 orange0 apple1 orange0 apple1 orange0 apple1 orangedtype: object...原创 2019-03-06 12:18:45 · 490 阅读 · 0 评论 -
正则表达式
学习网站:https://deerchao.net/tutorials/regex/regex.htm1.re.match:从头开始匹配,所以无法和“com”匹配re.match(‘www’,‘www.baidu.com’).span()(0, 3)b=re.match(‘com’,‘www.baidu.com’)b2.re.search():遍历查找匹配r...原创 2019-04-09 13:45:40 · 111 阅读 · 0 评论 -
to_datetime():把panda中的str变为datetime格式
data = ts.get_hist_data(‘510050’,start=‘2015-01-01’,end=‘2016-12-31’)data.index = pd.to_datetime(data.index)转载 2019-04-13 23:03:25 · 2274 阅读 · 0 评论 -
pd.read_excel
import xlrddata=pd.read_excel(‘pl_09/ZhaoyangHospital.xlsx’,sheetname=‘Sheet1’)data.head()购药时间 社保卡号 商品编码 商品名称 销售数量 应收金额 实收金额0 2016-01-01 星期五 1.616528e+06 236701.0 强力VC银...转载 2019-04-15 08:37:39 · 1447 阅读 · 0 评论 -
python中读取zip压缩文件
import zipfilewith zipfile.ZipFile(‘KaggleCredit2.csv.zip’,‘r’) as z:f=z.open(‘KaggleCredit2.csv’)data = pd.read_csv(f,index_col = 0)data.head()转载 2019-05-23 14:17:56 · 8678 阅读 · 1 评论 -
将txt数据读成矩阵形式
import numpy as npdata = np.genfromtxt(‘ex1data1.txt’,delimiter=’,’)X = data[:,0]y = data[:,1]转载 2019-05-23 15:42:00 · 1859 阅读 · 0 评论 -
pct_change()
官网链接:http://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.pct_change.html计算变化率:(后一个值-前一个值)/前一个值例如:s=pd.Series([1,2,3,4,5])s.pct_change()0 NaN1 1.0000002 0...原创 2019-02-01 23:14:48 · 17820 阅读 · 0 评论 -
tushare pro的token凭证码设置教程
一,从头像上点击用户名,打开个人主页;二,点击接口token,点击右边纸张图标,复制;在shell中进行如下操作:token=‘你复制下来的token’ts.set_token(token)pro=ts.pro_api()...原创 2019-01-13 18:33:07 · 20979 阅读 · 7 评论 -
dataframe中根据元素的值获取元素所在的坐标
参看文章https://blog.csdn.net/xwd18280820053/article/details/72614734/df=pd.DataFrame({“Boolcol”:[1,2,3,3,4],“attr”:[22,33,22,44,66]},index=[10,20,30,40,50])dfBoolcol attr10 1 2220 ...转载 2019-01-19 16:36:47 · 9140 阅读 · 0 评论 -
Pandas中DataFrame数据合并concat
df1=DataFrame(np.random.randn(3,4),columns=[‘a’,‘b’,‘c’,‘d’])df2=DataFrame(np.random.randn(2,3),columns=[‘b’,‘d’,‘a’])pd.concat([df1,df2]) a b c d 0 -0.848557 -1.163...转载 2019-01-19 19:56:28 · 3593 阅读 · 0 评论 -
pandas读取mysql中的数据
方法一:co=mdb.connect(host=“localhost”,user=“root”,db=“lqj”,passwd=“password”,use_unicode=True,charset=“utf8”)sql_cmd=“select * from test1”df = pd.read_sql(sql_cmd, co)dfid ts_code symbol ...转载 2019-01-20 10:37:02 · 2044 阅读 · 0 评论 -
正则表达式re
import re描绘一个或多个空白字符的正则表达式是\s+:text=“foo bar\t baz \tqux”re.split(’\s+’,text)[‘foo’, ‘bar’, ‘baz’, ‘qux’]转载 2019-01-21 10:57:00 · 134 阅读 · 0 评论 -
dataframe重新设置index
framea b c d0 0 7 one 01 1 6 one 12 2 5 one 23 3 4 two 04 4 3 two 15 5 2 two 26 6 1 two 3frame2=frame.set_index([‘c’,‘d’])#set_index函数会生成一个新的dataframe...原创 2019-01-21 15:27:19 · 27029 阅读 · 0 评论 -
Dataframe merge:inner,outer,left,right
import pandas as pdimport numpy as np#dataframe联合与合并数据集df1=pd.DataFrame({‘key’:[‘b’,‘b’,‘a’,‘c’,‘a’,‘a’,‘b’],‘data1’:range(7)})df2=pd.DataFrame({‘key’:[‘a’,‘b’,‘d’],‘data2’:range(3)})merge时只merge...原创 2019-01-21 15:41:18 · 6185 阅读 · 2 评论 -
pd.shift()
作用是后移一个位置。具体如下:a=pd.DataFrame({‘guangdong’:[2001,1002,2003],‘gansu’:[1,2,3],‘lilei’:[2002,2003,2004]},index=range(3))aguangdong gansu lilei0 2001 1 20021 1002 2 200...原创 2019-01-31 16:02:00 · 3993 阅读 · 0 评论 -
pd.diff()
求差,参数0 表示横轴,参数1表示纵轴,默认为0。举例如下:df=pd.DataFrame({‘a’:[1,2,3,4,5,6],‘b’:[1,1,2,3,5,8],‘c’:[1,4,9,16,25,36]})dfa b c0 1 1 11 2 1 42 3 2 93 4 3 164 5 5 255 6 8 36df...原创 2019-01-31 16:47:44 · 1305 阅读 · 0 评论 -
提取股票交易数据并对其进行分类
import sysimport numpy as npimport matplotlibmatplotlib.use(“TKAgg”)import matplotlib.pyplot as pltfrom matplotlib.collections import LineCollectionimport pandas as pdfrom sklearn import cluste...翻译 2019-01-21 23:11:58 · 2195 阅读 · 0 评论 -
从tushare中提取股票交易数据并进行聚类分析
import numpy as npimport pandas as pdimport tushare as tsimport MySQLdb as mdbimport matplotlibmatplotlib.use(“TkAgg”)import matplotlib.pyplot as pltfrom matplotlib.collections import LineColle...原创 2019-01-22 08:20:27 · 7722 阅读 · 2 评论 -
dataframe数据的反转(reverse)
方法1:data.reindex(index=data.index[::-1])方法2:data.iloc[::-1]举例如下:a=pd.DataFrame({‘gansu’:[2001,2002,2003],‘guangdong’:[2002,2005,2006],‘hunan’:[2003,2009,2010]},index=range(3))agansu guangdong...原创 2019-01-31 18:01:31 · 45263 阅读 · 1 评论 -
pandas ewm
在pandas 最新版中,ewma函数已经不可用了,但可以用ewm函数+mean()函数来代替。举例如下:df a b0 2001 20031 2002 20022 2003 2004df[‘a’].ewm(span=2).mean()0 2001.0000001 2001.7500002 2002.615385...转载 2019-02-01 10:28:42 · 15994 阅读 · 0 评论 -
pandas.io.data->pandas_datareader.data as web
pandas.io.data模块已不可用,现已由pandas_datareader.data模块代替例如经常用的:pandas.io.data as web 可转为pandas_datareader.data as web转载 2019-01-22 16:30:22 · 902 阅读 · 0 评论