数据帧列列表中产生KeyE的随机换行字符

2024-09-22 14:25:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个dataframe,我试图只获取列的一个子集,然后重命名这些列。你知道吗

req_cols = ['targetName','suiteName','configName','testName','actualResult_1','actualResult_2','explanation_1']

df = df[req_cols].rename(columns={'targetName':'tgt', 'suiteName':'suite', 'configName':'config', 'testName':'test', 'actualResult_2':'iresult', 'actualResult_1':'gresult', 'explanation_1':'explanation'})

我得到这个错误。你知道吗

raise KeyError('%s not in index' % objarr[mask])
KeyError: "['targetName' 'suiteName' 'configName' 'testName' 'actualResult_1'\n 'actualResult_2' 'explanation_1'] not in index"

为什么这个随机换行符出现在这个列列表中?你知道吗


Tags: indataframedfindexnotreq子集cols