starmoney.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import pandas as pd
  2. import numpy as np
  3. from pathlib import Path
  4. year = '2022'
  5. export_dir = f'/home/robert/Dropbox/Jugendchor 2000/Kasse/{year}/Export'
  6. kst = {'3115532': '0', '3123981': '1', '3124005': '2', '3123999': '3', '3124039': '4', '3123973': '5', '3124013': '6'}
  7. from_label = ['Buchungstag', 'Internet', 'Verwendungszweckzeile 1', 'Kommentar', 'KST',
  8. 'Verwendungszweckzeile 3', 'Verwendungszweckzeile 4', 'Verwendungszweckzeile 5',
  9. 'row_num', 'Einnahmen', 'Ausgaben']
  10. to_label = ['Datum', 'frei', 'Vorgang', 'Konto', 'KST', 'Nr.', 'Einnahmen_Kasse', 'Ausgaben_Kasse', 'Nr.', 'Einnahmen', 'Ausgaben']
  11. def import_csv(filename):
  12. kto = filename.name.split('_')[0]
  13. print(kto + ': ' + kst[kto])
  14. df: pd.DataFrame = pd.read_csv(filename, sep=';', decimal=',', encoding='utf-8', index_col=['IBAN', 'Laufende Nummer']).reset_index()
  15. df['Einnahmen'] = np.where(df['Betrag'] > 0, df['Betrag'], 0)
  16. df['Ausgaben'] = np.where(df['Betrag'] < 0, 0 - df['Betrag'], 0)
  17. df['KST'] = kst[kto]
  18. first_saldo = df.loc[0]['Saldo'] - df.loc[0]['Betrag']
  19. last_saldo = df.loc[len(df) - 1]['Saldo']
  20. df = df[df['Betrag'] != 0]
  21. df['row_num'] = np.arange(1, len(df) + 1)
  22. df = df[from_label]
  23. print(df.shape)
  24. first_row = [f'01.01.{year}', '', 'Anfangsbestand - SLS ' + kto, 'AB', kst[kto], '', '', '', 0, first_saldo, 0]
  25. last_row = [f'31.12.{year}', '', 'Endbestand - SLS ' + kto, 'EB', kst[kto], '', '', '', len(df) + 1, 0, last_saldo]
  26. df = pd.concat([
  27. pd.DataFrame([first_row], columns=from_label),
  28. df,
  29. pd.DataFrame([last_row], columns=from_label)
  30. ])
  31. print(df.shape)
  32. return df
  33. df = [import_csv(f) for f in Path(export_dir).glob('*.csv')]
  34. df_union: pd.DataFrame = pd.concat(df)
  35. print(df_union.shape)
  36. df_union = df_union.rename(columns=dict(zip(from_label, to_label)))
  37. df_union.to_csv(export_dir + '/export.csv.txt', sep=';', decimal=',', encoding='latin-1', index=False)