我有一个这样的数据帧。你知道吗
user tag1 tag2 tag3
0 Roshan ghai 0.0 1.0 1.0
1 mank nion 1.0 1.0 2.0
2 pop rajuel 2.0 0.0 1.0
3 random guy 2.0 1.0 1.0
我必须对每一行进行计算。对于每个元素x
x =(( specific tag's count for that user ##that element itself##))/ max no. of count of that tag ##max value of that column##)) * (ln(no. of total user ##lenth of df##)/(no. of of user having that tag ##no. of user having non 0 count for that particular tag or column ##))
我用###来描述这个特殊的值。我必须为dataframe的每个元素做这件事,什么是最有效的方法,因为我有大量的元素。我用的是python2.7。 输出:
user tag1 tag2 tag3
0 Roshan ghai 0 .287 0
1 mank nion .143 .287 0
2 pop rajuel .287 0 0
3 random guy .287 .287 0
我刚刚用了我写的mank nion和tag1的公式 x=((1.0)/2.0)*(ln(4/3)=.143。你知道吗
你可以试试这个:
然后创建一个函数,将行和这些值作为输入,并输出所需的三个值。并使用
apply
:可以首先通过^{} 选择没有第一列的所有值。然后使用^{} 、^{} 的非0值和^{} :
使用^{} 的另一种解决方案:
相关问题 更多 >
编程相关推荐