Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from bokeh.plotting import figure, show
- import datetime
- import pandas as pd
- def read(filename):
- with open('vin_data.txt') as f:
- s = f.read()
- return s
- def parse_string(s):
- x = s.split(',')
- year = int(x[0][-4:])
- month = int(x[1].split(' - ')[0])
- day = int(x[2].split(')')[0])
- vin = int(x[3])
- date = datetime.date(year, month, day)
- return (date, vin)
- def parse_data(s):
- ls = s[2:-3].split('], [')
- lx = [parse_string(s) for s in ls]
- return lx
- raw_data = read('vin_data.txt')
- list_of_tuples = parse_data(raw_data)
- df_vin = pd.DataFrame(list_of_tuples, columns=['date', 'vin'])
- df_vin = df_vin.groupby('vin').apply(min)
- df_vin_unique = df_vin.groupby('date').count()
- df_vin_unique['cumulative'] = df_vin_unique['vin'].cumsum()
- df_production = pd.DataFrame(
- {'date': [datetime.date(2017, x, 1) for x in [7, 8, 9, 10, 11, 12]],
- 'production': [0, 30, 75, 117, 145, 345]
- }
- )
- df_production['cumulative'] = df_production['production'].cumsum()
- f = figure(width=800,
- height=600,
- x_axis_type='datetime',
- title='Model 3 Estimated Sales vs. Unique Sightings Over Time')
- f.title.text_font_size = '18pt'
- f.xaxis.axis_label='date'
- f.yaxis.axis_label='cumulative number'
- f.line(df_vin_unique.index.values, df_vin_unique['cumulative'].values,
- legend='Cumulative number of unique sightings (based on VIN) [source: blfire.lima-city.de]',
- line_width=2)
- f.line(df_production['date'].values, df_production['cumulative'].values, color='red',
- legend = 'Cumulative number of estimated sales (interpolated) [source: insideevs.com]',
- line_width=2)
- f.legend.location = 'top_left'
- show(f)
Add Comment
Please, Sign In to add comment