Код: Выделить всё
def clean_charges(conn, cur):
charges = pd.read_csv('csv/all_charges.csv', parse_dates=['CreatedDate', 'PostingDate',
'PrimaryInsurancePaymentPostingDate',
'SecondaryInsurancePaymentPostingDate',
'TertiaryInsurancePaymentPostingDate'])
# Split charges into 10 equal sized dataframes
num_splits = 10
charges_split = np.array_split(charges, num_splits)
cur_month = datetime.combine(datetime.now().date().replace(day=1), datetime.min.time())
count = 0
total = 0
for cur_charge in charges_split:
for index, charge in cur_charge.iterrows():
if total % 1000 == 0:
print(total)
total += 1
# Delete it from the dataframe if its a charge from the current month
if charge['PostingDate'] >= cur_month:
count += 1
charges.drop(index, inplace=True)
continue
# Delete the payments if they were applied in the current month
if charge['PrimaryInsurancePaymentPostingDate'] >= cur_month:
charge['TotalBalance'] = charge['TotalBalance'] + charge['PrimaryInsuranceInsurancePayment']
charge['PrimaryInsurancePayment'] = 0
if charge['SecondaryInsurancePaymentPostingDate'] >= cur_month:
charge['TotalBalance'] = charge['TotalBalance'] + charge['SecondaryInsuranceInsurancePayment']
charge['SecondaryInsurancePayment'] = 0
if charge['TertiaryInsurancePaymentPostingDate'] >= cur_month:
charge['TotalBalance'] = charge['TotalBalance'] + charge['TertiaryInsuranceInsurancePayment']
charge['TertiaryInsurancePayment'] = 0
# Delete duplicate payments
if charge['AdjustedCharges'] - (charge['PrimaryInsuranceInsurancePayment'] + charge['SecondaryInsuranceInsurancePayment'] +
charge['TertiaryInsuranceInsurancePayment'] + charge['PatientPaymentAmount']) != charge['TotalBalance']:
charge['SecondaryInsurancePayment'] = 0
charges = pd.concat(charges_split)
charges.to_csv('csv/updated_charges.csv', index=False)
Я буду признателен за любую помощь, которую смогу выяснить. почему это работает так медленно!
Подробнее здесь: https://stackoverflow.com/questions/791 ... 0-000-rows
Мобильная версия