starmoney.py 1.9 KB

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