Explaining efficiency improvement using loops related to Exclusion process and Replacement process I've done it, but I will explain how to make "replacement" more efficient in a loop with a very similar pattern.
This is not a programming term. As introduced in this article, it is a process of "if a certain character string is included, replace it with another character string".
It's an application of replacement.
For example, "I want to make the department name written in the abbreviation on the invoice statement the official name" or "I want to make the product name written in the abbreviation on the order form the official name". think.
Replacement @ field item
sashikae_list = (("If this is included 1","Please replace it with this 1"),
("If this is included 2","Please replace it with this 2"),
("If this is included 3","Replace it with this 3"))
for i in sashikae_list:
if i[0] in field_value:
field_value = i[1]
The explanation is [this area] of the replacement edition (https://qiita.com/IQ_Bocchi/items/83ae1dedfc1de6962006#%E3%82%BA%E3%83%90%E3%83%AA%E3%82%84%E3 % 82% 8A% E3% 81% 8B% E3% 81% 9F% E7% BD% AE% E6% 8F% 9B% E3% 81% AE% E5% A0% B4% E5% 90% 88) please. It's almost the same mechanism.
Replacement @ table
sashikae_list = (("If this is included 1","Please replace it with this 1"),
("If this is included 2","Please replace it with this 2"),
("If this is included 3","Replace it with this 3"))
def table_sashikae(x,y):
for i in y:
if i[0] in x:
x = i[1]
return x
df['Column name'] = df['Column name'].apply(table_sashikae,y=sasihkae_list)
How was it?
This time, the mechanism is the same as Replacement processing and Replacement loop. Since it is only processed by the structure, the explanation is not so thick.
If you have any questions, please leave a comment on this article or contact us via DM on Twitter.
Recommended Posts