嗨,我想合并python数据帧中的记录
当前数据帧
Date Value Date Description Amount
01/07/2019 01/07/2019 CHEQUE WITHDRAW 1000.00
01/07/2019 01/07/2019 SUNDRY CREDIT CAPITAL FUND FEES 100.00
02/07/2019 02/07/2019 CHEQUE WITHDRAW 10.00
02/07/2019 02/07/2019 SUNDRY CREDIT FROM HEAD OFFICE 10.00
02/07/2019 02/07/2019 CHEQUE WITHDRAW 50.00
Expected dataframe
Date Value Date Description Amount
01/07/2019 01/07/2019 CHEQUE WITHDRAW 1000.00
01/07/2019 01/07/2019 SUNDRY CREDIT CAPITAL FUND FEES 100.00
02/07/2019 02/07/2019 CHEQUE WITHDRAW 10.00
02/07/2019 02/07/2019 SUNDRY CREDIT FROM HEAD OFFICE 10.00
02/07/2019 02/07/2019 CHEQUE WITHDRAW 50.00
获取错误密钥错误:26
我试着遍历行,找到amount列null并与description合并,然后删除该行
for index, row in df.iterrows():
if (pd.isnull(row[3]) == True):
df.loc[index-1][2] = str(df.loc[index-1][2]) + ' ' + str(df.loc[index][0])
df.drop([index],inplace=True)
您可以尝试以下方法(在本文末尾,您可以找到我的测试数据):
这会返回如下结果:
您可以使用以下代码生成的数据来测试:
相关问题 更多 >
编程相关推荐