Pandas 计算皮尔逊';多维特征的s系数
我有一个数据框,其中每行对应一个样本,每列代表一个特征。现在,我的一个列是一个字符串列,其中包含类似“这是一个红苹果”的文本。我怎样才能将其转换为一种形式,使pearson的相关矩阵可以针对该数据帧进行计算? 类似地,我还有另一列,它接收标识符列表 以下是一个例子:Pandas 计算皮尔逊';多维特征的s系数,pandas,correlation,pearson,Pandas,Correlation,Pearson,我有一个数据框,其中每行对应一个样本,每列代表一个特征。现在,我的一个列是一个字符串列,其中包含类似“这是一个红苹果”的文本。我怎样才能将其转换为一种形式,使pearson的相关矩阵可以针对该数据帧进行计算? 类似地,我还有另一列,它接收标识符列表 以下是一个例子: id text list_of_ids score1 score2 1. "This is An apple" [1, 2, 3, 4]
id text list_of_ids score1 score2
1. "This is An apple" [1, 2, 3, 4] 4.6. 1.0
2. "This is An orange" [1, 5, 6] 5.2 1.4
使用-
输出
col1 col2 col3 col4 An This apple is orange
0 This is An apple [1, 2, 3, 4] 4.6 1.0 1 1 1 1 0
1 This is An orange [1, 5, 6] 5.2 1.4 1 1 0 1 1
然后,您可以使用删除不需要的列,如果字数会变得非常大怎么办?这仍然是计算相关性的正确方法吗?
col1 col2 col3 col4 An This apple is orange
0 This is An apple [1, 2, 3, 4] 4.6 1.0 1 1 1 1 0
1 This is An orange [1, 5, 6] 5.2 1.4 1 1 0 1 1