csv_kontenrahmen.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import pandas as pd
  2. import numpy as np
  3. base_dir = (
  4. "V:\\Kunden\\Luchtenberg\\1 Umstellung SKR51\\GCStruct_Modell\\Kontenrahmen\\"
  5. )
  6. source_csv = base_dir + "Kontenrahmen_Export.csv"
  7. mul_csv = base_dir + "Kontenrahmen_mul.csv"
  8. result_csv = base_dir + "Kontenrahmen_Vorlage.csv"
  9. df_source = pd.read_csv(
  10. source_csv,
  11. decimal=",",
  12. sep=";",
  13. encoding="latin-1",
  14. converters={i: str for i in range(0, 200)},
  15. )
  16. df_source["Konto_Klasse"] = df_source["Konto_Nr"].str.slice(0, 1)
  17. df_source["Konto_Art"] = np.where(
  18. df_source["Konto_Klasse"].isin(["4", "5", "7", "8"]), "2", "1"
  19. )
  20. df_mul = pd.read_csv(
  21. mul_csv,
  22. decimal=",",
  23. sep=";",
  24. encoding="latin-1",
  25. converters={i: str for i in range(0, 200)},
  26. )
  27. df_join = df_source.merge(
  28. df_mul, how="inner", on=["Konto_Klasse"], suffixes=[None, "_other"]
  29. )
  30. df_join["Konto_Nr"] = df_join["Konto_Nr"] + "_" + df_join["Suffix"]
  31. df_join.drop(["Konto_Klasse", "Suffix"], axis=1, inplace=True)
  32. df_source.drop(["Konto_Klasse"], axis=1, inplace=True)
  33. df_join = df_join.append(df_source).sort_index()
  34. df_join.to_csv(result_csv, decimal=",", sep=";", encoding="latin-1", index=None)