我有以下数据框:
df = pd.DataFrame([([40.33, 40.34, 40.22],[-71.11, -71.21, -71.14],[12, 45, 10]), ([41.23, 41.40, 41.22],[-72.01, -72.01, -72.01],[11, 23, 15]), ([43.33, 43.34],[-70.11, -70.21],[12, 40]), ([41.23, 41.40], [-72.01, -72.01, -72.01], [11, 23, 15])], columns=['long', 'lat', 'accuracy'])
long lat accuracy
[40.33, 40.34, 40.22] [-71.11, -71.21, -71.14] [12, 45, 10]
[41.23, 41.40, 41.22] [-72.01, -72.01, -72.01] [11, 23, 15]
[43.33, 43.34] [-70.11, -70.21] [12, 40]
[41.23, 41.40] [-72.01, -72.01, -72.01] [11, 23, 15]
...
每一列都包含一个浮点数列表。我想检查所有三列的每一行中,这些列表的大小是否相同。最好的方法是什么?如果所有列表的大小相同,则返回另一个名为sanity
的列,返回TRUE
;如果至少一个列表的大小与其他列表不同,则返回FALSE
?
预期输出为:
long lat accuracy sanity
[40.33, 40.34, 40.22] [-71.11, -71.21, -71.14] [12, 45, 10] TRUE
[41.23, 41.40, 41.22] [-72.01, -72.01, -72.01] [11, 23, 15] TRUE
[43.33, 43.34] [-70.11, -70.21] [12, 40] TRUE
[41.23, 41.40] [-72.01, -72.01, -72.01] [11, 23, 15] FALSE
2条答案
按热度按时间pb3s4cty1#
您可以使用
applymap
和nunique
来解决此问题:输出:
vngu2lb82#