![](/img/trans.png)
[英]Getting different behavior between regex results on Windows vs Linux
[英]Pandas .equals method returns different results between windows and linux
我正在嘗試使用conda在windows10上部署相同的代碼,並且在 linux 上工作的單元測試在windows上沒有function 。
在 Ubuntu 上:
df_1
col_1 col_2 col_3
0 [-] 1 nul
1 [-] 1 pas top
2 [+, plus_small] 2 personal-minute du centre
3 [+, plus_small] 2 top
4 [+, plus_small] 2 tres bien
當我們查看細節時
df_1.to_dict()
{
'col_1': {0: ['-'], 1: ['-'], 2: ['+', 'plus_small'], 3: ['+', 'plus_small'], 4: ['+', 'plus_small']},
'col_2': {0: 1, 1: 1, 2: 2, 3: 2, 4: 2},
'col_3': {0: 'nul', 1: 'pas top', 2: 'personal-minute du centre', 3: 'top', 4: 'tres bien'}
}
當我們查看細節時
df_2
col_1 col_2 col_3
0 [-] 1 nul
1 [-] 1 pas top
2 [+, plus_small] 2 personal-minute du centre
3 [+, plus_small] 2 top
4 [+, plus_small] 2 tres bien
df_2.to_dict()
{
'col_1': {0: ['-'], 1: ['-'], 2: ['+', 'plus_small'], 3: ['+', 'plus_small'], 4: ['+', 'plus_small']},
'col_2': {0: 1, 1: 1, 2: 2, 3: 2, 4: 2},
'col_3': {0: 'nul', 1: 'pas top', 2: 'personal-minute du centre', 3: 'top', 4: 'tres bien'}
}
結果
df_1.equals(df_2)
True
在 Windows10 上:
df_1
col_1 col_2 col_3
0 [-] 1 nul
1 [-] 1 pas top
2 [+, plus_small] 2 personal-minute du centre
3 [+, plus_small] 2 top
4 [+, plus_small] 2 tres bien
當我們查看細節時
{
'col_1': {0: ['-'], 1: ['-'], 2: ['+', 'plus_small'], 3: ['+', 'plus_small'], 4: ['+', 'plus_small']},
'col_2': {0: 1, 1: 1, 2: 2, 3: 2, 4: 2},
'col_3': {0: 'nul', 1: 'pas top', 2: 'personal-minute du centre', 3: 'top', 4: 'tres bien'}
}
df_2
col_1 col_2 col_3
0 [-] 1 nul
1 [-] 1 pas top
2 [+, plus_small] 2 personal-minute du centre
3 [+, plus_small] 2 top
4 [+, plus_small] 2 tres bien
當我們查看細節時
df2.to_dict()
{
'col_1': {0: ['-'], 1: ['-'], 2: ['+', 'plus_small'], 3: ['+', 'plus_small'], 4: ['+', 'plus_small']},
'col_2': {0: 1, 1: 1, 2: 2, 3: 2, 4: 2},
'col_3': {0: 'nul', 1: 'pas top', 2: 'personal-minute du centre', 3: 'top', 4: 'tres bien'}
}
df_1 == df_2
col_1 col_2 col_3
0 True True True
1 True True True
2 True True True
3 True True True
4 True True True
接着:
df_1.equals(df_2)
False
我可以用to_dict==替換.equals方法
前:
df_1.equals(df_2)
False
后:
df_1.to_dict() == df_2.to_dict()
True
謝謝@Ch3steR 的想法!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.