12345678910111213141516171819202122232425262728293031323334353637 |
- import pandas as pd
- from pathlib import Path
- import json
- filename = Path(__file__).parent / 'Planung' / 'Marketingplanung_AHR_2022_V1.xls'
- output = Path(__file__).parent / 'export' / 'marketing_2022.json'
- sheets = [
- 'Verarbeitung_Plan_MM', 'Verarbeitung_Plan_KRU', 'Verarbeitung_Plan_ULM',
- 'Verarbeitung_Plan_LL', 'Verarbeitung_Plan_GZ',
- 'Verarbeitung_Plan_GÖG', 'Verarbeitung_Plan_GÖG_MOT'
- ]
- columns = [
- 'Betrieb Nr', 'Konto Nr',
- 'Wert1', 'Wert2', 'Wert3', 'Wert4', 'Wert5', 'Wert6',
- 'Wert7', 'Wert8', 'Wert9', 'Wert10', 'Wert11', 'Wert12'
- ]
- xls = pd.read_excel(filename, sheet_name=sheets)
- xls['Verarbeitung_Plan_GÖG']['Betrieb Nr'] = '82'
- xls['Verarbeitung_Plan_GÖG_MOT']['Betrieb Nr'] = '81'
- xls_select = [sheet[columns] for sheet in xls.values()]
- df = pd.concat(xls_select).groupby(['Konto Nr', 'Betrieb Nr']).sum()
- # df.reset_index(inplace=True)
- dict_split = df.to_dict(orient='split')
- res = {}
- for index, data in zip(dict_split['index'], dict_split['data']):
- kto, dept = index
- if kto not in res:
- res[kto] = {}
- res[kto][dept] = data
- json.dump(res, open(output, 'w'), indent=2)
|