csv_kontenrahmen.py 1.1 KB

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