import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
s= pd.Series([1,2,3,np.nan,5,6,]) #series 类型数组。
s
dates= pd.date_range("20170112",periods=6) #Creating a DataFrame by passing a numpy array, with a datetime index and labeled column
dates
list(dates)
dates.date
list(dates.date)
dates.year
list(dates.year)
list(dates.day)
str(dates.date)
df=pd.DataFrame(np.random.randn(6,4),index=dates,columns=list("ABCD"))
df
df2 = pd.DataFrame({
'A' : 1.,
'B' : pd.Timestamp('20130102'),
'C' : pd.Series(1,index=list(range(4)),dtype='float32'),
'D' : np.array([3] * 4,dtype='int32'),
'E' : pd.Categorical(["test","train","test","train"]),
'F' : 'foo' }) #Creating a DataFrame by passing a dict of objects that can be converted to series-like.
df2
df2.dtypes
df.dtypes
df2.<TAB> #使用jupyter时按tab键,可以看到代码提示。
df.head()
df.index
df.columns
df.values
df.describe()
df
df.T
df.sort_index(axis=1,ascending=False) #Sorting by an axis 排序。
df.sort_values(by="B") #Sorting by values
df
df["A"]# Selecting a single column, which yields a Series, equivalent to df.A
df.A
df[0:3] #Selecting via [], which slices the rows.
df["2017-01-13":"2017-01-17"]
dates
df.loc[dates[0]] #For getting a cross section using a label
df.loc[:,["A","B"]]
df.loc['20170112':'20170116',['A','B']] #Showing label slicing, both endpoints are included
df.loc["20170115",["A","B"]]
df.loc[dates[3],"D"] #For getting a scalar value
df.at[dates[3],"D"] #For getting fast access to a scalar (equiv to the prior method)
df.iloc[3] #Select via the position of the passed integers
df.iloc[2:5,0:2] # By integer slices, acting similar to numpy/python
df.iloc[[1,3,4],[0,2]] #By lists of integer position locations, similar to the numpy/python style
df.iloc[1:3,:]
df.iloc[:,1:3]
df.iloc[1,1] #For getting a value explicitly
df.iat[1,1] #For getting fast access to a scalar (equiv to the prior method)
df[df.A>0] #Using a single column’s values to select data
df[df>0] #Selecting values from a DataFrame where a boolean condition is met
df2
df
df2=df.copy()
df2
df.equals(df2)
df==df2
df is df2
df2["E"]=["one","one","two","three","four","three"]
df2
df2[df2.E.isin(["two","four"])]
df2[df2["E"].isin(["two","four"])]
s1= pd.Series([1,2,3,4,5,6],index=pd.date_range("20171016",periods=6)) #Setting a new column automatically aligns the data by the indexes
s1
df.at[dates[0],"A"]=0 #Setting values by label
df
df.iat[0,1]=0
df
df.loc[:,"D"]=np.array([5]*len(df)) #Setting by assigning with a numpy array
df
df2=df.copy()
df2
df2[df2>0]=-df2
df2
df
df1 = df.reindex(index=dates[0:4], columns=list(df.columns) + ['E'])
df1.loc[dates[0]:dates[1],'E'] = 1
df1
df1.dropna(how="any") #To drop any rows that have missing data
df1.fillna(value=5) # Filling missing data
df1
pd.isnull(df1)
df1.isnull()
df1.isna() #没有这个方法~~
df
df.mean()
df.mean(1) #Same operation on the other axis
s= pd.Series([1,2,3,np.nan,4,5],index=dates).shift(2)
# Operating with objects that have different dimensionality and need alignment. In addition, pandas automatically broadcasts along the specified dimension.
s
df
df.sub(s,axis="index") #dataFrame与series的减法
df
df.apply(np.cumsum) #行叠加。
df.apply(lambda x: x.max()-x.min())
s= pd.Series(np.random.randint(0,7,size=10))
s
s.value_counts()
s= pd.Series(['A', 'B', 'C', 'Aaba', 'Baca', np.nan, 'CABA', 'dog', 'cat'])
s.str.lower()
s
df
df=pd.DataFrame(np.random.randn(10,4))
df
# break it into pieces
pieces=[df[:3],df[3:7],df[7:]]
pd.concat(pieces)
pieces
left=pd.DataFrame({
"key":["foo","foo"],"lval":[1,2]})
right = pd.DataFrame({
'key': ['foo', 'foo'], 'rval': [4, 5]})
left
right
pd.merge(left,right,on="key")
left = pd.DataFrame({
'key': ['foo', 'bar'], 'lval': [1, 2]})
right = pd.DataFrame({
'key': ['foo', 'bar'], 'rval': [4, 5]})
left
right
pd.merge(left,right,on="key")
df = pd.DataFrame(np.random.randn(8, 4), columns=['A','B','C','D'])
df
s=df.iloc[3]
s
df.append(s,ignore_index=True)
df = pd.DataFrame({
'A' : ['foo', 'bar', 'foo', 'bar',
'foo', 'bar', 'foo', 'foo'],
'B' : ['one', 'one', 'two', 'three',
'two', 'two', 'one', 'three'],
'C' : np.random.randn(8),
'D' : np.random.randn(8)})
df
df.groupby("A").sum()
df.groupby(["A","B"]).sum() #Grouping by multiple columns forms a hierarchical index, which we then apply the function.
tuples = list(zip([['bar', 'bar', 'baz', 'baz',
'foo', 'foo', 'qux', 'qux'],
['one', 'two', 'one', 'two',
'one', 'two', 'one', 'two']]))
tuples
tuples = list(zip(*[['bar', 'bar', 'baz', 'baz',
'foo', 'foo', 'qux', 'qux'],
['one', 'two', 'one', 'two',
'one', 'two', 'one', 'two']]))
tuples
index=pd.MultiIndex.from_tuples(tuples,names=["first","second"])
index
df=pd.DataFrame(np.random.randn(8,2),index=index,columns=['A', 'B'])
df
df2=df[:4]
df2
stacked= df2.stack()
stacked
stacked.unstack()
stacked.unstack(1)
stacked.unstack(0)
df = pd.DataFrame({
'A' : ['one', 'one', 'two', 'three'] * 3,
'B' : ['A', 'B', 'C'] * 4,
'C' : ['foo', 'foo', 'foo', 'bar', 'bar', 'bar'] * 2,
'D' : np.random.randn(12),
'E' : np.random.randn(12)})
df
pd.pivot_table(df,values="D",index=["A","B"],columns=["C"])
rng=pd.date_range("1/2/2017",periods=100,freq="S")
rng
ts =pd.Series(np.random.randint(0,500,len(rng)),index=rng)
ts
ts.resample("5Min").sum()
ts.resample("1Min").sum()
rng= pd.date_range("2/1/2017 00:00",periods=5,freq="D")
rng
ts=pd.Series(np.random.randn(len(rng)),index=rng)
ts
tsUtc=ts.tz_localize("UTC")
tsUtc
tsUtc.tz_convert("US/Eastern")
tsUtc
rng=pd.date_range("1/8/2017",periods=5,freq="M")
rng
ts=pd.Series(np.random.randn(len(rng)),rng)
ts
ps=ts.to_period()
ps
ps.to_timestamp()
ps
prng=pd.period_range("1990Q1","2017Q4",freq="Q-NOV")
prng
ts= pd.Series(np.random.randn(len(prng)),prng)
ts.head()
ts.index=(prng.asfreq("M","e")+1).asfreq("H","s")+9
ts.head()
df = pd.DataFrame({
"id":[1,2,3,4,5,6],"raw_grade":["a","a","c","b","b","f"]})
df
df["grade"]=df.raw_grade.astype("category")
df
df.grade #Convert the raw grades to a categorical data type
# Rename the categories to more meaningful names (assigning to Series.cat.categories is inplace!)
df.grade.cat.categories=["very good","good","nomal","bad"]
df
# Reorder the categories and simultaneously add the missing categories (methods under Series .cat return a new Series per default).
df.grade=df.grade.cat.set_categories(["very bad", "bad", "medium","good", "very good"])
df.grade
df
df.sort_values(by="grade")
df.groupby("grade").size()
ts=pd.Series(np.random.randn(1000),index=pd.date_range("1/1/2017",periods=1000))
ts.head()
ts=ts.cumsum()
ts.head()
ts.plot()
df=pd.DataFrame(np.random.randn(1000,4),index=ts.index,columns=["A","B","C","D"])
df.head()
df=df.cumsum()
plt.figure()
df.plot()
plt.legend(loc="best")
plt.show()
df.to_csv("foo.csv")
pd.read_csv("foo.csv")
df.to_hdf("foo.h5","df")
pd.read_hdf("foo.h5","df")
df.to_excel('foo.xlsx', sheet_name='Sheet1')
pd.read_excel('foo.xlsx', 'Sheet1', index_col=None, na_values=['NA'])
文章浏览阅读1.9w次,点赞47次,收藏173次。1. 地址相关概念1. 物理地址(physical address) 物理内存,真实存在的插在主板内存槽上的内存条的容量的大小. 内存是由若干个存储单元组成的,每个存储单元有一个编号,这种编号可唯一标识一个存储单元,称为内存地址(或物理地址)。我们可以把内存看成一个从0字节一直到内存最大容量逐字节编号的存储单元数组,即每个存储单元与内存地址的编号相对应。_浮动目标码模块
文章浏览阅读653次。使用@RestControllerAdvice注解对项目可能产生的异常进行统一处理。_spring mvc 统一异常处理
文章浏览阅读2.5k次,点赞3次,收藏22次。P3 串口电路一键下载原理分析上拉电路三极管b为基极,c为集电极,e为发射极作开关使用时,NPN型三极管:b接低电平,则电路截止,b接高电平则电路饱和导通;PNP型三极管:b接高电平,则电路截止,b接低电平则电路饱和导通P5 初识STM32PCB打样选择深圳嘉立创公司引脚顺序:从黑点开始逆时针旋转为正方向写好的程序编译之后都是一条条指令,存放在 FLASH中,内核要读取这些指令来执行程序就必须通过 ICode 总线..._32单片机学习资料
文章浏览阅读6.1k次,点赞2次,收藏4次。RxJava源码分析之subscribeOn和observeOnRxJava的特色就是可以改变他的任务线程,可以很优雅的在子线程和主线程中切换,而切换用到的两个主要方法是subscribeOn()和observeOn().备注:因本人水平有限,以下分析只代表本人所见,如有不当,请见谅并指出。subscribeOn()和observeOn()的区别subscr_subscribeon observeon
文章浏览阅读1.6k次,点赞4次,收藏19次。读完这篇文章里你能收获到:1 学会SQLServer中IF/WHILE/CASE逻辑控制语句用法,2 提供实际操作的案例SQL脚本_sqlserver if用法
文章浏览阅读720次。Postman—命令行执行脚本、生成报告、Jenkins持续集成_postman 命令行
文章浏览阅读4.3k次,点赞3次,收藏4次。Office文件在线预览是目前移动化办公的一种新趋势。Office在线预览指的是Office系列的文件在线查看而不依附域客户端的存在。在浏览器或者浏览器控件中可以预览查看Word、PDF、Excel、OFD、PPT等格式文档。usdoc文档在线服务正是为了解决这一问题而做出了优化的访问,充分发挥了前后端结合的优势,提供更好的阅读体验,Office在线预览指的是Office系列的文件在线查看而不依附域客户端的存在。在浏览器或者浏览器控件中可以预览查看Word、PDF、Excel、OFD、PPT等格式文档地址_ofd在线预览
文章浏览阅读413次。jQuery开发者社区应该是网站开发中最勤奋和活跃的社区之一了。他们源源不断的为我们提供免费而又实用的插件。我把最近搜集到的40个非常实用的插件分享给大家。 一、滚动插件jQuery WaypointsWaypoints 是一个 jQuery 用来实现捕获各种滚动事件的插件,例如实现无翻页的内容浏览,或者固定某个元素不让滚动等等。支持主流浏览器版本。 _jquery 页面可视控制插件
文章浏览阅读1.5w次,点赞30次,收藏62次。芯片包1. 下载芯片包官方下载链接:http://www.keil.com/dd2/pack/这次安装的是GD32F30x系列的芯片包将芯片包下载到Keil_5的安装根目录下。2. 安装芯片包双击芯片包.pack文件点击Next安装中。。。点击Finish完成打开Keil_5新建工程,芯片包已经安装好了。..._gd32芯片包
文章浏览阅读378次。【100个】计算机理论英文参考文献供您参考,希望能解决毕业生们的计算机理论论文参考文献哪里找相关问题,整理好参考文献那就开始写计算机理论论文吧!一、计算机理论论文参考文献范文[1]抑制OFDM信号峰均比的PTS算法分析与优化.胡茂凯.陈西宏.刘强,2011陕西省电子学会“信息感知与三网融合”前沿技术学术研讨会[2]基于有性繁殖的小生境遗传算法与多峰函数优化.田玉龙.吴清.赵卫国,2007第18届全..._计算机取证英语文献
文章浏览阅读1.8k次。报错:Error connecting to the service protocol: HttpException: Connection closed before full header was received, uri = http://127.0.0.1:52491/Z2UadkBDgn8=/ws原因:可能是因为android版本太高,从Q换成P就可以了我用的f..._flutter error: httpexception: invalid proxy configuration proxy null:null, i
文章浏览阅读768次。Polaris(14G)服务器前面板的LCD液晶屏该如何使用呢?(PS:Polaris服务器前面板的LCD液晶屏是选配部件,如果没有加配则没有LCD液晶显示屏)首先,给大家解释下每个按钮的功能:只有三个按钮,操作是不是很简单呀,具体有哪些强大的功能大家可以在官网下载对应机型的手册具体查看下面举两个常用的例子:1、查看报错信息服务器前面板LCD显示屏如果是黄色的话,此时LCD液晶屏会滚动报错信息,我..._戴尔服务器t640 配显示器