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'])
文章浏览阅读404次。每一个 JVM 线程都拥有一个私有的 JVM 线程栈,用于存放当前线程的 JVM 栈帧(包括被调用函数的参数、局部变量和返回地址等)。如果某个线程的线程栈空间被耗尽,没有...
文章浏览阅读1.2k次,点赞2次,收藏6次。javascript 原生实现 Vue.js的路由切换功能,模拟单页应用上效果图:源码如下:<!-- author:helang Email:[email protected]><!DOCTYPE html><html lang="en"><head> <meta charset="U..._js将数组转化成vue路由的形式
文章浏览阅读1.1k次,点赞24次,收藏17次。set容器和multiset容器详解。第一次接触对组的概念。使用中要小心迭代过程中插入或者删除元素迭代器迭代器失效的可能性。_c++ set容器
文章浏览阅读1k次。在ASCII中,回车(CR)字符用十进制值13或十六进制值0x0D表示,换行(LF)字符用十进制值10或十六进制值0x0A表示。这两个字符通常一起使用,表示将光标移到下一行的开头位置。CRLF在许多操作系统和编程环境中被广泛使用,例如Windows中的文本文件和网络通信中的协议,如HTTP和SMTP。它们是文本格式化和解析的重要元素。_crlf
文章浏览阅读256次。函数再战—熟练基础,精通技能,触类旁通之所以又整理了一遍函数,主要是因为当我进行后续学习的时候,发现函数比想象的要NB的多,于是又厚着脸皮又来了一遍,嗯,果然很NB。建议在学习的过程中遇到了难题,记得回头复习复习,也许正是那些你忽略的内容,给未来的你营造出自己是SB的难题。内容概括:函数基本语法及特性函数与局部变量返回值嵌套函数递归匿名函数函数式编程介绍高阶函数内置函数..._全栈开发与数学
文章浏览阅读921次。1 检查一下release模式下的链接器的输入,其依赖的lib名称最后一个字母是没有"d",d代表debug如图:2 检查一下路径,看是否因为带中文的路径导致编码错误..._visual studio的debug模式可以include opencv release模式不行
文章浏览阅读5.5k次。下载plc程序;a.插上线时,设置PG/PC接口会出现下载线的名字,可以单击进行修改参数,设置和PLC一样的参数(这里的地址对应接口0,1)就可以通信了;b.记住PLC上的两个接口0,1接口,不要改plc软件中的系统块参数。下载触摸屏程序;a.需要注意的是在MCGS中,设置通用串口父设备中选择COM2,COM2是485通信,然后设置设备0(PLC S7-200)中的设备地址,这里的地址对应与PLC中系统块的地址,不是实际的接口号0,1;b设置触摸屏通信地址:断电重启触摸屏。开机后.._plc和触摸屏如何通信
文章浏览阅读311次。如今使用 CI/CD 工具是网页应用程序开发的一个必要条件。作为关键开发路径的一部分,加快构建系统的速度对于提高开发人员的生产效率是至关重要的。原文地址:5 Strategies to R..._cicd优化
文章浏览阅读3.5k次,点赞4次,收藏5次。Crank Storyboard Suite是一个十分容易学习的用来设计嵌入式界面的软件,软件可以导出为Android上可执行的apk文件。下面从最简单的例子开始,建立一个如下所示的界面,上面的图标有按下的效果。1)选择File->New->Storyboard Application新近一个工程。2. 在工程里面的文件夹里_crank_storyboard_suite-v5.3.0
文章浏览阅读1.0k次。1. 前言众所周知,Python 最流行的爬虫框架是 Scrapy,它主要用于爬取网站结构性数据今天推荐一款更加简单、轻量级,且功能强大的爬虫框架:feapder项目地址:https://github.com/Boris-code/feapder2. 介绍及安装和 Scrapy 类似,feapder 支持轻量级爬虫、分布式爬虫、批次爬虫、爬虫报警机制等功能内置的 3 种爬虫如下: AirSpider 轻量级爬虫,适合简单场景、数据量少的爬虫 Spider._feapder 网盘
文章浏览阅读6k次,点赞2次,收藏6次。关注“Java后端技术全栈”回复“面试”获取全套大厂面试资料程序=数据结构+算法这好比是软件工程师的“武林秘籍”。数据结构指的是数据与数据之间的逻辑关系;算法指的是解决特定问题的步骤和方..._数据结构与算法分析java语言描述pdf
文章浏览阅读8w次,点赞111次,收藏691次。参考链接https://www.bilibili.com/video/BV1JE411g7XF?p=54https://arxiv.org/abs/1706.03762https://blog.csdn.net/qq_36653505/article/details/83375160简述自注意力机制(self-attention)self-attention可以视为一个特征提取层,给定输入特征a1,a2,⋅⋅⋅ana^{1},a^{2},\cdot \cdot \cdot a^{n}a1,a2_自注意力机制代码