<jupyter_start><jupyter_text>Generate cost data<jupyter_code>input_path = '../input_static/level_of_service/'<jupyter_output><empty_output><jupyter_text>PT ticket pricesThe German rail operator provides a distance-related ticket price list as pdf that can be translated into a function<jupyter_code>input_file = input_path + 'DB_2020_preisliste_fahrplanjahr_2020.pdf'
# generate a DataFrame
db_prices = tabula.read_pdf(input_file, output_format='dataframe', pages=list(range(5, 41)), pandas_options={
    'names': ['km', 'single_trip_second_class', 'single_trip_first_class', 'return_trip_second_class', 'return_trip_first_class']
}, multiple_tables=False)[0]
db_prices.dropna(axis=0, how='any', inplace=True)
db_prices.dtypes
db_prices
for col in list(db_prices.columns):
    db_prices[col] = db_prices[col].str.replace(',', '.')
db_prices = db_prices[[col for col in list(db_prices.columns)]].astype(float)
# plot
db_prices.set_index('km').plot()
# save
db_prices.to_csv(input_file.replace('.pdf', '.csv'), index=False)
# Use second class single trip prices
# Choose a fit for a distance range up to 60 km (longer links are rare)
z = np.polyfit(c.loc[0:30, 'km'], c.loc[0:30, 'single_trip_second_class'], deg=1)
p = np.poly1d(z)
plt.plot(c.loc[0:30, 'km'], p(c.loc[0:30, 'km']), linestyle='--', marker=' ', label='Regression')
plt.plot(c.loc[0:30, 'km'], c.loc[0:30, 'single_trip_second_class'], linestyle='--', marker=' ', label='2nd class')
plt.legend()
rail_short_intercept = np.round(z[1], 3)
print('y={}*x+{}'.format(np.round(z[0], 3), rail_short_intercept))<jupyter_output><empty_output><jupyter_text>MIT costThe German car driver association (ADAC) provides a list of cost for every new car available in Germany. They calculate aquisition cost, variable cost, fix cost, and repair cost.<jupyter_code>input_file = input_path + 'ADAC_2019_autokostenuebersicht_47085.pdf'
# generate a DataFrame
cars = tabula.read_pdf(input_file, output_format='dataframe', pages=list(range(3, 38)), pandas_options={
    'names': ['model', 'data', 'costs']
}, multiple_tables=False)[0]
cars.sample(5)
# cleansing
cars.reset_index(inplace=True)
cars.rename(columns={'model': 'power', 'index': 'model'}, inplace=True)
cars.dropna(axis=0, how='all', inplace=True)
cars.dropna(axis=0, how='any', thresh=3, inplace=True)
cars = cars.loc[cars['model']!='NaN']
cars.dropna(axis=0, subset=['model'], inplace=True)
cars = cars.loc[cars['model']!='Marke / Modell:']
cars['costs'] = cars['costs'].str.replace(',', '.')
cars['costs'] = cars['costs'].str.replace('*', '')
elements = ['fix_cost', 'repair_cost', 'var_cost', 'acquisition_cost', 'eur_per_month', 'ct_per_km']
cars[elements] = cars['costs'].str.split(' ', expand=True)
# Save
elements.append('model')
cars = cars[elements]
cars.to_csv(input_file.replace('.pdf', '.csv'), index=False)<jupyter_output><empty_output><jupyter_text>Take only perceived variable cost for distance-dependency.Assume monthly mileage of 15,000km / 12Additionally, there are fix cost which add up on every trip. Assume 3 trips per day as average.<jupyter_code>vc_car = cars['var_cost'].astype(int).mean() / (15000000/12) # in EUR/m
vc_car
fix_car = cars['fix_cost'].astype(int).mean() / 30 / 3
fix_car<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1711378353376503, 'fraction_numerical': 0.024360160345359236, 'mean_word_length': 7.604774535809018, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '478033', 'license': 'MIT', 'n_tokens_mistral': 1246, 'n_tokens_neox': 1168, 'n_words': 243, 'path': 'notebooks/prep3x_data_tables.ipynb', 'repo_name': 'marlinarnz/quetzal_germany', 'size': '3243'}