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'])
文章浏览阅读157次。pom.xml:<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.or_java 逆向工程 generatorconfiguration
文章浏览阅读523次。目录前置知识JVM指令码指令码编辑Javassist使用场景基本使用常见插入方法添加异常代码块总结方法拷贝特殊语法特殊语法表$0, $1, $2$args$$$cflow$r$w$_$sig$class创建类实例访问类实例变量参考链接:https://www.cnblogs.com/sunfie/p/5154246.html前置知识JVM指令码Java源代码不能直接运行,需要编译成class文件,然后被JVM加载后运行。Class文件是由JVM指令码所组成的,JVM加载Class文件,就是在加载Cl_ctmethod
文章浏览阅读559次。Maven介绍Maven是项目管理工具,对软件项目提供构建与依赖管理。Maven是Apache下的Java开源项目。Maven为Java项目提供了统一的管理方式,已成为业界标准。Maven核心特性项目设置遵循统一的规则,保证不同开发环境的兼容性。强大的依赖管理,项目依赖组件自动下载、自动更新。可扩展的插件机制,使用简单,功能丰富。Maven的安装与配置安装Maven之前需要安装jdk1.8。从官网下载MavenMaven官网:https://maven.apache.org/bin
文章浏览阅读1.9k次。一、C #中Sort()函数的使用与C++中类似,C#中也有自己的Sort()函数,其使用方式:(列表List的排序使用方式)第一步:声明一个myComparer类,它继承自IComparer:class myComparer : IComparer<MyPoint>/*实现 IComparer<T> 接口中的 Compare 方法, ..._c# 获取list 下表
文章浏览阅读1.7w次,点赞16次,收藏17次。Python从入门到精通零基础入门篇
文章浏览阅读1.1k次。大家都知道,java中JDBC中,有个预处理功能,这个功能一大优势就是能提高执行速度尤其是多次操作数据库的情况,再一个优势就是预防SQL注入,严格的说,应该是预防绝大多数的SQL注入。 用法就是如下边所示:[java] view plain copyString sql="update cz_zj_directpayment dp_java sql prepare的作用
文章浏览阅读290次。systemctl enable\start /usr/lib/systemd/system/xxx.service`则会报标题所示的错误。去掉路径,直接systemctl enable\start xxx.service则不会报错。xxx.service放入到/usr/lib/systemd/system下之后,如果以。_failed to start usr-lib-systemd-system-mode_exporter.service.mount: unit not
文章浏览阅读617次,点赞8次,收藏8次。本文介绍了无人直播系统的功能和优势,以及如何进行开发。无人直播系统能够实时采集、编码和传输视频流,支持弹幕互动,并具备实时性、互动性、灵活性和可扩展性等优势。开发无人直播系统的方法包括确定需求、设计系统架构、实现功能、部署上线和维护优化。通过定制开发无人直播系统,可以满足不同业务场景下的实时视频传输和互动需求,提供高质量的直播体验。_无人直播系统源码
文章浏览阅读539次。嘿嘿,我刚上研一,体育方面的研究生,想做计算机视觉方面的课题,这几天都在配置opencv和tensorflow的环境,走了不少歪路,总结了一下。一、关于opencv源码的查看和编译:http://blog.csdn.net/poem_qianmo/article/details/21974023 这个网址介绍的很全。其中要注意的是:如果安装的是vs2017,那么current generato...
文章浏览阅读84次。在“设置”应用中,找到“应用程序”或“应用管理器”选项,然后找到默认浏览器应用。点击该应用,然后找到“存储”或“存储空间”选项,点击进入。在存储页面中,找到“清除数据”或“清除缓存”选项,并点击确认。在Android设备上,打开“设置”应用,并找到“应用程序”或“应用管理器”选项。点击该应用,然后找到“清除默认值”或“清除默认设置”的选项,并点击确认。在“设置”应用中,找到“应用程序”或“应用管理器”选项,然后找到另外一个浏览器应用。点击该应用,然后找到“清除数据”或“清除缓存”选项,并点击确认。
文章浏览阅读4.4k次。实际项目中,上传文件时实际可能需要传输一个token。方法一:1、查看vue antdesign文档https://vue.ant.design/components/upload-cn/2、使用customRequestcustomRequest 通过覆盖默认的上传行为,可以自定义自己的上传实现 Function3、定义customRequest,之前定义action行为会被覆盖,可以注释掉4、customRequest代码如下customRequest ._ant design vue 上传
文章浏览阅读4.9k次,点赞12次,收藏92次。C/C++ 是一门底层、细粒度、功能强大、学习曲线陡峭的语言,掌握这门语言的程序员通常有着更长的生命周期以及更深的护城河。但入门门槛高也是不争的事实,这篇文章把C++学习划分为入门、进阶、深入三个阶段,每步提供相应的学习方法和资源,帮助大家更好地掌握这门语言。_c++学习路线