esproc vs python 1 增删改查

 

1. 增加记录:在第二的位置增加一条记录

esproc


A

1

=now()

2

=file("C:\\Users\\Sean\\Desktop\\esproc_vs_python\\EMPLOYEE.txt")

3

=A2.import@t()

4

>A3.insert(2,100:EID,"wang":NAME,"lao":SURNAME,"Femal":GENDER,"CA":STATE,date("1999-1-1"):BIRTHDAY,date("2009-3-4"):HIREDATE,"HR":DEPT,3000:SALARY)

5

=interval@ms(A1,now())

A4:添加一条记录(“:”前表示字段值,“:”后表示字段),其中2表示第二条记录的位置

A5:计算运算时间(interval():计算时间间隔。@ms表示以毫秒为单位)

python

import time

import pandas as pd

import datetime

import numpy as np

import random

s=time.time()

data = pd.read_csv("C:/Users/Sean/Desktop/esproc_vs_python/EMPLOYEE.txt",sep="\t")

values=[100,"wang","lao","Femal","CA","1999-01-01","2009-03-04","HR",3000]

line_dic={}

for i in range(len(data.columns)):

    line_dic[data.columns[i]]=values[i]

line = pd.DataFrame(line_dic,index=[1])

data = pd.concat([data.loc[:0],line,data.loc[1:]],ignore_index=True)

print(data)

e=time.time()

print(e-s)

pd.concat[df1,df2,…,dfn))达到新增记录的目的,dataframe结构的记录是从0开始计数的,如df.loc[1:]表示切片取出第二条以后的所有记录

最后计算出运算耗时。

结果:

esproc

python


耗时

esproc

0.004

python

0.039

 

2. 删除记录:删除第 2 条记录

esproc                     


A

1

=now()

2

=file("C:\\Users\\Sean\\Desktop\\esproc_vs_python\\EMPLOYEE.txt")

3

=A2.import@t()

4

>A3.delete(2)

5

=interval@ms(A1,now())

A4:删除第2条记录

python

import time

import pandas as pd

import datetime

import numpy as np

import random

s=time.time()

data = pd.read_csv("C:/Users/Sean/Desktop/esproc_vs_python/EMPLOYEE.txt",sep="\t")

data = data.drop(1)

print(data)

e=time.time()

print(e-s)

利用df.drop()函数删除某条记录

结果:

esproc

python

 


耗时

esproc

0.003

python

0.034

 

3.修改记录:第 5 条记录的 NAME 改为 aaa,SALARY 改为 1000

esproc


A

1

=now()

2

=file("C:\\Users\\Sean\\Desktop\\esproc_vs_python\\EMPLOYEE.txt")

3

=A2.import@t()

4

>A3.modify(5,"aaa":NAME,1000:SALARY)

5

=interval@ms(A1,now())

A4:修改第5条记录中的NAME字段的值为“aaa”,修改SALARY字段的值为1000

python

import time

import pandas as pd

import datetime

import numpy as np

import random

s=time.time()

data = pd.read_csv("C:/Users/Sean/Desktop/esproc_vs_python/EMPLOYEE.txt",sep="\t")

data.loc[4,['NAME','SALARY']]=['aaa',1000]

print(data)

e=time.time()

print(e-s)

利用df.loc[]切片取出第5条记录的NAME,SALARY字段并赋值为‘aaa’和1000

结果:

esproc

python


耗时

esproc

0.003

python

0.037

 

4.查询行:查询第 2~10 条记录

esproc


A

1

=now()

2

=file("C:\\Users\\Sean\\Desktop\\esproc_vs_python\\EMPLOYEE.txt")

3

=A2.import@t()

4

=A3(to(2,10))

5

=interval@ms(A1,now())

A4to(m,n):产生m~n的序列,我们用T表示序表,A表示序列。T(A)表示取出序列中包含值的记录,这里表示取出第2~10条记录

python

import time

import pandas as pd

import datetime

import numpy as np

import random

s=time.time()

data = pd.read_csv("C:/Users/Sean/Desktop/esproc_vs_python/EMPLOYEE.txt",sep="\t")

data = data.loc[1:9]

print(data)

e=time.time()

print(e-s)

利用df.loc[]切片取出第2~10条记录

结果:

esproc

python


耗时

esproc

0.003

python

0.023

 

5.增加列:增加一个字段 Fullname

esproc


A

1

=now()

2

=file("C:\\Users\\Sean\\Desktop\\esproc_vs_python\\EMPLOYEE.txt")

3

=A2.import@t()

4

=A3.derive(NAME+""+SURNAME:Fullname)

5

=interval@ms(A1,now())

A4derive()增加字段,这里表示用原来的NAMESURNAME连接生成Fullname字段。

python

import time

import pandas as pd

import datetime

import numpy as np

import random

s=time.time()

data = pd.read_csv("C:/Users/Sean/Desktop/esproc_vs_python/EMPLOYEE.txt",sep="\t")

data['Fullname'] = data['NAME']+data['SURNAME']

print(data)

e=time.time()

print(e-s)

取出NAMESURNAME合并成Fullname

结果:

esproc

python

 


耗时

esproc

0.004

python

0.037

 

6.筛选字段:筛选出字段 NAME,SURNAME,STATE,GENDER

esproc


A

1

=now()

2

=file("C:\\Users\\Sean\\Desktop\\esproc_vs_python\\EMPLOYEE.txt")

3

=A2.import@t()

4

=A3.new(NAME,SURNAME,STATE,GENDER)

5

=interval@ms(A1,now())

A4T.new()生成新的序表。这里表示生成包含A3序表中NAME,SURNAME,STATE,GENDER这几个字段的新序表。

python

import time

import pandas as pd

import datetime

import numpy as np

import random

s=time.time()

data = pd.read_csv("C:/Users/Sean/Desktop/esproc_vs_python/EMPLOYEE.txt",sep="\t")

data = data[['NAME','SURNAME','STATE','GENDER']]

print(data)

e=time.time()

print(e-s)

取出NAME,SURNAME,STATE,GENDER这几个字段复制给新的dataframe

结果:

esproc

python


耗时

esproc

0.002

python

0.022

 

7.修改字段名:修改 EID 为 ID

esproc


A

1

=now()

2

=file("C:\\Users\\Sean\\Desktop\\esproc_vs_python\\EMPLOYEE.txt")

3

=A2.import@t()

4

=A3.rename(EID:ID)

5

=interval@ms(A1,now())

A4rename()修改字段名。这里表示将EID修改为ID

python

import time

import pandas as pd

import datetime

import numpy as np

import random

s=time.time()

data = pd.read_csv("C:/Users/Sean/Desktop/esproc_vs_python/EMPLOYEE.txt",sep="\t")

data.rename(columns={'EID':'ID'},inplace=True)

print(data)

e=time.time()

print(e-s)

利用df.rename()函数修改字段名,将EID修改为ID。参数inplace控制是否修改原来的dataframe结构。

结果:

esproc

python


耗时

esproc

0.002

python

0.030

 

小结:我们通过对记录和字段的增、删、改、查这些基本的运算,用esprocpython按照相同的思路,对相同的数据进行同样的处理,在描述效率方面,两者相差并不大,都很方便而且容易上手。


EMPLOYEE.txt