更改为from_dict时,不推荐使用的方法from_items会引发错误

问题描述 投票:1回答:1

我正在寻找修复一个即将被解释的方法qazxsw poi与建议的qazxsw poi

from_items

当我在df赋值时更改为from_dict

pd.set_option('display.max_columns', 50)
pd.set_option('display.max_rows', 50)

Test_Data = [('originating_system_id', ['CL', 'CL', 'CL', 'CL']),
             ('security_type1', ['CORP', 'CORP', 'CORP', 'CORP']),
             ('state', ['Traded', 'Covered', 'Traded Away', 'Traded']),
             ('trading_book', ['LCAAAAA', 'NUBBBBB', 'EDFGSFG', 'PDFEFGR'])
             ]
df = pd.DataFrame.from_items(Test_Data)
print(df)

  originating_system_id     security_type1        state trading_book
0                    CL               CORP       Traded      LCAAAAA
1                    CL               CORP      Covered      NUBBBBB
2                    CL               CORP  Traded Away      EDFGSFG
3                    CL               CORP       Traded      PDFEFGR

我希望应用过滤器时出现以下行错误:

from_dict

df = pd.DataFrame.from_dict(Test_Data) 结构不同吗?有没有替代m1 = ~df['trading_book'].str.startswith(tuple(prefixes)) KeyError: 'trading_book'

python pandas dataframe
1个回答
1
投票

对我来说工作很好,将其转换为字典:

from_dict

详情:

from_items
© www.soinside.com 2019 - 2024. All rights reserved.