![](/img/trans.png)
[英]Why does numpy.random.Generator.choice provides different results (seeded) with given uniform distribution compared to default uniform distribution?
[英]Using modin provides different results compared to Pandas default
当我在modin中使用 pandas 和使用pandas
default 时,我得到不同的结果
print(selection_weights.head())
country league Win DNB O 1.5 U 4.5
0 Africa Africa Cup of Nations 3.68 1.86 5.2 1.45
1 Africa Africa Cup of Nations U17 2.07 1.50 3.3 1.45
2 Africa Africa Cup of Nations U20 2.07 1.50 3.3 1.45
3 Africa Africa Cup of Nations U23 2.07 1.50 3.3 1.45
4 Africa African Championship Women 2.07 1.50 3.3 1.45
print(historical_games.head())
Unnamed: 0 home_odds draw_odds away_odds country league datetime home_team away_team home_score away_score
0 0 1.36 4.31 7.66 Brazil Copa do Nordeste 2020-02-07 00:00:00 Sport Recife Imperatriz 2 2
1 1 2.62 3.30 2.48 Brazil Copa do Nordeste 2020-02-02 22:00:00 ABC America RN 2 1
2 2 5.19 3.58 1.62 Brazil Copa do Nordeste 2020-02-02 00:00:00 Frei Paulistano Nautico 0 2
3 3 2.06 3.16 3.50 Brazil Copa do Nordeste 2020-02-02 22:00:00 Botafogo PB Confianca 1 1
4 4 2.19 2.98 3.38 Brazil Copa do Nordeste 2020-02-02 22:00:00 Fortaleza Ceara 1 1
当我在默认pandas
中运行以下代码时,输出是所需的:
import pandas as pd
selection_db = historical_games.loc[:, historical_games.columns.intersection(['country', 'league'])]
selection_db = selection_db.drop_duplicates()
selection_db = selection_db.sort_values(['country', 'league'], ascending=[True, True])
selection_db.loc[:, 'Win'] = 1.1
selection_db.loc[:, 'DNB'] = 0.7
selection_db.loc[:, 'O 1.5'] = 3.2
selection_db.loc[:, 'U 4.5'] = 2.2
ids = ['country', 'league']
selection_db = selection_db.set_index(ids)
selection_db.update(selection_weights.drop_duplicates(ids).set_index(ids))
selection_db = selection_db.reset_index()
selection_weights = selection_db
print(selection_weights.head())
country league Win DNB O 1.5 U 4.5
0 Africa Africa Cup of Nations 3.68 1.86 5.2 1.45
1 Africa Africa Cup of Nations U17 2.07 1.50 3.3 1.45
2 Africa Africa Cup of Nations U20 2.07 1.50 3.3 1.45
3 Africa Africa Cup of Nations U23 2.07 1.50 3.3 1.45
4 Africa African Championship Women 2.07 1.50 3.3 1.45
但是当我用modin
运行它时,我得到一个不同且不正确的输出
import os
import ray
ray.init()
os.environ["MODIN_ENGINE"] = "ray"
import modin.pandas as pd
selection_db = historical_games.loc[:, historical_games.columns.intersection(['country', 'league'])]
selection_db = selection_db.drop_duplicates()
selection_db = selection_db.sort_values(['country', 'league'], ascending=[True, True])
selection_db.loc[:, 'Win'] = 1.1
selection_db.loc[:, 'DNB'] = 0.7
selection_db.loc[:, 'O 1.5'] = 3.2
selection_db.loc[:, 'U 4.5'] = 2.2
ids = ['country', 'league']
selection_db = selection_db.set_index(ids)
selection_db.update(selection_weights.drop_duplicates(ids).set_index(ids))
selection_db = selection_db.reset_index()
selection_weights = selection_db
print(selection_weights.head())
country league
0 Africa 2.2
1 Africa 2.2
2 Africa 2.2
3 Africa 2.2
4 Africa 2.2
问题是我必须将函数作为大型工作流程的一部分运行,并且当我在开始时导入 modin 时,它会按预期执行直到这部分代码。
虽然我无法在代码之间恢复为默认熊猫,或者我不知道如何在代码之间更改库。
我该如何解决这种情况?
@Harshad,来自 Modin GitHub 的这条评论描述了如何将 Modin 数据框转换为 pandas:使用df._to_pandas()
。 一旦有了 pandas 数据框,就可以在其上调用任何 pandas 方法。 来自同一问题的其他评论描述了如何将 pandas 数据帧转换回 Modin 数据帧:调用modin.pandas.DataFrame(pandas_dataframe)
。
关于您看到的 Modin 错误,我的猜测是您添加列的selection_db.loc[:, 'Win'] = 1.1
之类的行会引发KeyError
并且根本不会更改 Modin 数据框。 这是一个已知的 Modin 错误, https://github.com/modin-project/modin/issues/4354 。 例如,这适用于熊猫
import pandas
df = pandas.DataFrame([[1]])
df.loc[:, 'a'] = 3
但是如果我尝试使用import modin.pandas as pandas
和最新版本的 Modin 的相同脚本(提交 c1d5dbd71efb8fb5806fad41959794182780fc25),我得到 KeyError KeyError: array(['a'], dtype='<U1')
。 您是否有可能收到KeyError
并忽略它?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.