大家好,我有一个数据框,其中的列是这样的。列:
在这个数据框中,每一行都是一个具有所有这些列属性的观察。我的任务是计算变量P,然后针对 x 回归 p,针对 y 回归 p,最后针对 (x 和 y) P=(具有 y 值且丢失的移动次数)/(具有价值的移动总数y)
我的问题是为我的小组寻找P。我不知道如何以 Pythonic 的方式来处理这个我可以手动循环并计算所有但即使这样我也不确定如何处理它,而且我的数据框的大小可能需要很长时间
WhiteR,BlackR,EMV,MovePlayedValue,NewGame,NinePtLead,AverageRating,Rating_Group,length_of_checkmate
1880.0,1865.0,27.0,27.0,1,useless,1875,1800,0
1880.0,1865.0,22.0,21.0,1,useless,1875,1800,0
1865.0,1880.0,25.0,25.0,1,useless,1875,1800,0
1880.0,1865.0,24.0,19.0,1,useless,1875,1800,0
1865.0,1880.0,22.0,22.0,1,useless,1875,1800,0
1880.0,1865.0,27.0,27.0,1,bigLeadLost,1875,1800,2
如果我正确理解您的问题:您想要导致失败的 y 类型的频率(非零类型),除以 y 的总移动数(y 的类型):
import pandas as pd
import numpy as np
df = {'WhiteR': [1880.0,1880.0,1865.0,1880.0,1865.0,1880.0],\
'BlackR': [1865.0,1865.0,1880.0,1865.0,1880.0,1865.0],\
'EMV': [27.0,22.0,25.0,24.0,22.0,27.0,],\
'MovePlayedValue':[27.0,21.0,25.0,19.0,22.0,27.0,],\
'NewGame':[1,1,1,1,1,1],\
'NinePtLead':['useless','useless','useless','useless','useless','bigLeadLost'],\
'AverageRating':[1875,1875,1875,1875,1875,1875],\
'Rating_Group':[1800,1800,1800,1800,1800,1800,],\
'length_of_checkmate':[0,0,0,0,0,2]}
df = pd.DataFrame(df)
status=df['length_of_checkmate'].value_counts().reset_index().rename(columns={'index':
'length_of_checkmate', 'length_of_checkmate': 'Freq.'})
df1 = pd.merge(df, status, on = ('length_of_checkmate'))
df1['P']= (df1['Freq.']/df1['length_of_checkmate']).replace(np.inf, 0)
#then proceed to 'Regress p against x, regress p against y and finally p against (x and y)'
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句