小编Ire*_*ark的帖子

Pandas DataFrame apply()ValueError:解压缩的值太多(预期2)

我刚刚开始探索Python,虽然我很兴奋,但我似乎远非蟒蛇思维.

以下是一种方法示例,其中包含"次优"一词.虽然这对我相对较小的数据集来说已经足够了,但我想知道如何更好地编写它?

import pandas as pd
from pandas import DataFrame

# create sample log data frame
lg = pd.DataFrame(['Access violation at address 00A97...',
                   'Try to edit the splines or change...',
                   'Access violation at address 00F2B...',
                   'Please make sure the main electro...'], columns=['lg_msg'])

# define message classification
err_messages = [['Access violation', 'ACC-VIOL', 'PROG'],
                ['Please make sure th', 'ELE-NOT-PLACED', 'MOD'],
                ['Try to edit the splines', 'TRY-EDIT-SPLINES', 'MOD']]                

# lookup code
def message_code(msg_text):
    for msg in err_messages:
        if msg_text.startswith(msg[0]):
            return msg[1]
    return '' …
Run Code Online (Sandbox Code Playgroud)

python lambda pandas

6
推荐指数
1
解决办法
4478
查看次数

标签 统计

lambda ×1

pandas ×1

python ×1