您好,登錄后才能下訂單哦!
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 |
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 |
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 |
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()) |
A4:to(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 |
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()) |
A4:derive()增加字段,這里表示用原來的NAME和SURNAME連接生成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)
取出NAME和SURNAME合并成Fullname
結果:
esproc
python
耗時 | |
esproc | 0.004 |
python | 0.037 |
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()) |
A4:T.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 |
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()) |
A4:rename()修改字段名。這里表示將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 |
小結:我們通過對記錄和字段的增、刪、改、查這些基本的運算,用esproc和python按照相同的思路,對相同的數據進行同樣的處理,在描述效率方面,兩者相差并不大,都很方便而且容易上手。
EMPLOYEE.txt
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。