在进行子设置时,列的所有值都转换为NaN

2024-04-25 12:11:11 发布

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

我正在学习bokeh并从真正的python学习a tutorial

在教程中,它将一个排名数据集子集为两个团队,并生成以下结果。我得到了完全相同的结果,只是我的game won列被转换为NaN。你知道为什么会这样吗

west_top_2 = standings[(standings['teamAbbr'] == 'HOU') | (standings['teamAbbr'] == 'GS')]\
        .loc[:,['stDate','teamAbbr','gamewon']].sort_values(['teamAbbr','stDate'])

       stDate teamAbbr  gameWon
9   2017-10-17       GS        0
39  2017-10-18       GS        0
69  2017-10-19       GS        0
99  2017-10-20       GS        1
129 2017-10-21       GS        1

我的输出

    stDate       teamAbbr  gamewon
9   2017-10-17       GS      NaN
39  2017-10-18       GS      NaN
69  2017-10-19       GS      NaN
99  2017-10-20       GS      NaN
129 2017-10-21       GS      NaN

Tags: 数据gsgamebokeh教程nan团队tutorial
1条回答
网友
1楼 · 发布于 2024-04-25 12:11:11

你的陈述中有一个拼写错误,这是正确的:

west_top_2 = (standings[
    (standings['teamAbbr'] == 'HOU') | (standings['teamAbbr'] == 'GS')
].loc[:, ['stDate', 'teamAbbr', 'gameWon']].sort_values(['teamAbbr','stDate']))

你少了一个括号和一个大写的“W”

相关问题 更多 >