【发布时间】:2020-09-05 00:53:37
【问题描述】:
我有一个带有标签和用户名的数据集:
Labels Usernames
1 Londonderry
1 Londoncalling
1 Steveonder43
0 Maryclare_re
1 Patent107391
0 Anonymous
1 _24londonqr
...
我需要证明包含单词 London 和标签 1 的用户名之间存在相关性。为此,我创建了第二个标签来查看单词 London 的位置
for idx, username in df['Usernames']:
if 'London' in username:
df['London'].iloc[idx] = 1
else:
df['London'].iloc[idx] = 0
然后我比较了这些二元变量,使用 Pearson 相关系数:
import scipy.stats.pearsonr as rho
corr = rho(df['labels'], df['London'])
但是它不起作用。 我在上述步骤中遗漏了什么吗?
【问题讨论】:
标签: python pandas scipy pearson-correlation