Pandas 下面的行需要很多时间来更新,因为它有将近2.5l的记录
在一个数据帧中,我使用了不止一个的组计数,需要更新这些索引sepcific列值,因为它的2.5l内存错误,所以它失败了。有什么快速解决方案吗Pandas 下面的行需要很多时间来更新,因为它有将近2.5l的记录,pandas,Pandas,在一个数据帧中,我使用了不止一个的组计数,需要更新这些索引sepcific列值,因为它的2.5l内存错误,所以它失败了。有什么快速解决方案吗 gl_no=primary.groupby('GL Account').filter(lambda x:len(x)>1) primary_index=primary[primary['GL Account'].isin(gl_no['GL Account'])].index primary.loc[primary_index]['Cost Elem
gl_no=primary.groupby('GL Account').filter(lambda x:len(x)>1)
primary_index=primary[primary['GL Account'].isin(gl_no['GL Account'])].index
primary.loc[primary_index]['Cost Element']='01'
primary.loc[primary_index]['GL Acc Type']='P'
您可以对布尔掩码使用with和comparing,并通过以下方式设置新值:
这是一个很好的解释,我永远不会忘记这一点,谢谢你的详细解释。
primary = pd.DataFrame({
'Cost Element':list('abcdef'),
'GL Acc Type':list('abcdef'),
'GL Account':list('aadbbc')
})
print (primary)
Cost Element GL Acc Type GL Account
0 a a a
1 b b a
2 c c d
3 d d b
4 e e b
5 f f c
mask=primary.groupby('GL Account')['GL Account'].transform('size') > 1
primary.loc[mask, ['Cost Element','GL Acc Type']] = ['01', 'P']
print (primary)
Cost Element GL Acc Type GL Account
0 01 P a
1 01 P a
2 c c d
3 01 P b
4 01 P b
5 f f c