Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Esproc vs python 1 addition, deletion, modification and query

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

1. Add record: add a record to the second position

Esproc

A1=now () 2=file ("C:\\ Users\\ Sean\\ Desktop\\ esproc_vs_python\\ EMPLOYEE.txt") 3=A2.import@t () 4 > A3.insert (2Power100 NAME 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 Magazine now ())

A4: add a record (field value before ":" and field after ":"), where 2 indicates the location of the second record

A5: calculate the operation time (interval (): calculate the interval. @ ms means in milliseconds)

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,100, "wang", "lao", "Femal", "CA", "1999-01-01", "2009-03-04", "HR", 3000]

Line_dic= {}

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

Line_ [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 (eMurs)

Use pd.concat ([df1,df2, … , dfn) to add new records. Records in dataframe structure are counted from 0. For example, Df.Lok [1:] indicates that all records after the second entry is removed from the slice.

Finally, it is calculated that the operation takes time.

Results:

Esproc

Python

Time-consuming esproc0.004python0.0392. Delete record: delete Article 2 record

Esproc

A1=now () 2=file ("C:\\ Users\\ Sean\\ Desktop\\ esproc_vs_python\\ EMPLOYEE.txt") 3=A2.import@t () 4 > A3.delete (2) 5=interval@ms (A1 Magi now ())

A4: delete Article 2 record

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 (eMurs)

Delete a record by using the df.drop () function

Results:

Esproc

Python

Time-consuming esproc0.003python0.0343. Modify the record: change the NAME recorded in Article 5 to aaa,SALARY to 1000

Esproc

A1=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: modify the value of the NAME field in the fifth record to "aaa" and the value of the SALARY field to 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 (eMurs)

The NAME,SALARY field of the fifth record is extracted by df.loc [] slice and assigned to 'aaa' and 1000'.

Results:

Esproc

Python

Time-consuming esproc0.003python0.0374. Query line: query item 2 / 10 record

Esproc

A1=now () 2=file ("C:\\ Users\\ Sean\\ Desktop\\ esproc_vs_python\\ EMPLOYEE.txt") 3=A2.import@t () 4=A3 (to (2je 10)) 5=interval@ms (A1 Magi now ())

A4:to (m) n: we use T to denote the order table and A to represent the sequence. T (A) means to take out the records containing values in the sequence. Here, it means to take out the 2nd to 10th records.

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 (eMurs)

Using df.loc [] slice to take out the 2nd ~ 10th record

Results:

Esproc

Python

Time-consuming esproc0.003python0.0235. Add column: add a field Fullname

Esproc

A1=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 Magi now ())

A4:derive () adds a field, which means that the Fullname field is generated with the original NAME and SURNAME connection.

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 (eMurs)

Take out NAME and SURNAME and merge them into Fullname

Results:

Esproc

Python

Time-consuming esproc0.004python0.0376. Filter field: filter out field NAME,SURNAME,STATE,GENDER

Esproc

A1=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 () generates a new ordinal table. This means to generate a new sequence table that contains the fields NAME,SURNAME,STATE,GENDER in the A3 sequence table.

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 (eMurs)

Take out the fields of NAME,SURNAME,STATE,GENDER and copy them to the new dataframe.

Results:

Esproc

Python

Time-consuming esproc0.002python0.0227. Modify field name: change EID to ID

Esproc

A1=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 () modifies the field name. This means to change EID to 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 (eMurs)

Use the df.rename () function to modify the field name and change EID to ID. The parameter inplace controls whether the original dataframe structure is modified.

Results:

Esproc

Python

Time-consuming esproc0.002python0.030

Summary: through the basic operations of adding, deleting, changing and checking records and fields, we use esproc and python to deal with the same data in the same way of thinking. In terms of description efficiency, there is little difference between them, which is very convenient and easy to use.

EMPLOYEE.txt

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report