回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>Python中是否有其他函数可以用来对客户的事务进行分组?假设一个事务中包含一个特定的词,并且有多个具有相同名称的事务,然后将它们组合在一起。你知道吗</p>
<p>我用了这个代码,但它太长了,因为我有来自不同商家的数千个独特的交易。你知道吗</p>
<pre><code>temp=tranx.TRANX.fillna("0")
tranx['Activity_2'] = pd.np.where(temp.str.contains("PNP "),"PICKNPAY",
pd.np.where(temp.str.contains("CHECKERS"), "CHECKERS",
pd.np.where(temp.str.contains("MRPRICE"), "MRPRICE",
pd.np.where(temp.str.contains("FOOD LOVER"), "FOODLOVERMARKET",
pd.np.where(temp.str.contains("DISCHEM"), "DISCHEM",
pd.np.where(temp.str.contains("DIS-CHEM"), "DISCHEM",
pd.np.where(temp.str.contains("OK FOODS"), "OKFOODS",
pd.np.where(temp.str.contains("DISCHEM"), "DISCHEM",
pd.np.where(temp.str.contains("FASHION EXPRESS"), "FASHIONEXPRESS",
pd.np.where(temp.str.contains("MTC"), "MTC",
pd.np.where(temp.str.contains("TELECOM"), "TELECOM",
pd.np.where(temp.str.contains("KFC"), "KFC",
pd.np.where(temp.str.contains("ACKERMANS"), "ACKERMANS",
pd.np.where(temp.str.contains("SHOPRITE"), "SHOPRITE",
pd.np.where(temp.str.contains("USAVE"), "SHOPRITE",
pd.np.where(temp.str.contains("S/STATION"), "SERVICESTATION",
pd.np.where(temp.str.contains("SERVICE STATION"), "SERVICESTATION",
pd.np.where(temp.str.contains("SOULSTICE DAY SPA"), "SOULSTICESPA",
pd.np.where(temp.str.contains("CLICKS" ), "CLICKS",
pd.np.where(temp.str.contains("JET "), "JET",
pd.np.where(temp.str.contains("PEP "), "PEP",
pd.np.where(temp.str.contains("WOERMANN"), "WOERMANN", "OTHER"))))))))))))))))))))))
</code></pre>
<p>我是否无法创建一个包含所有商户的列表,然后在每一行中循环一次,以确定商户名称是否出现在该行中,如果是,则输出商户名称,如果否,则将交易分类为其他?你知道吗</p>
<p>以下是数据示例:</p>
<p><a href="https://i.stack.imgur.com/96lO4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/96lO4.png" alt="Transactions Sample"/></a></p>