I have a python code that scrapes data from a Script element on a HTML web page. However, the data saved in the csv file (1) is not in the format I want; (2) has extra content not needed. I only want the data for the orange and blue lines and their date. Here is the screenshot of the Canvas on the web page that I need to read data from:
Python code (Partial):
# Locate Edge driver
driver = webdriver.Edge(executable_path="C://Windows//SysWOW64//MicrosoftWebDriver.exe")
# Locate the canvas script element for daily active & peak current players data
Canvas_script = driver.find_element_by_css_selector('body > center > div > div:nth-child(15) > div:nth-child(1) > script')
# Get script content
Canvas_script_data = Canvas_script.get_attribute('innerHTML')
# Create and save data to csv
filename = datetime.now().strftime('C:/Users/username/Desktop/Output/Canvas_data_%Y%m%d_%H%M.csv')
with open(filename, 'w', newline='', encoding="utf-8") as csvfile:
wr = csv.writer(csvfile)
wr.writerow([Canvas_script_data])
print("Canvas data is saved. ")
time.sleep(3)
The code was executed successfully and the data was saved in the csv file. However, everything was saved in the beginning cell of the csv file, which is not what I want.
Current CSV output:
Desired CSV Output: (Data is made up for viewing. Header is not necessary)
Script element snippet from the web page:
<script>
var plotActions = null;
$J(document).ready( function() {
$J.jqplot.config.enablePlugins = true;
plotActions = $J.jqplot(
'actions_graph'
, [ [['2019-02-18',27],['2019-02-19',42],['2019-02-20',39],['2019-02-21',40],['2019-02-22',37],['2019-02-23',11],['2019-02-24',28],['2019-02-25',37],['2019-02-26',36],['2019-02-27',39],['2019-02-28',36],['2019-03-01',27],['2019-03-02',13],['2019-03-03',24],['2019-03-04',27],['2019-03-05',27],['2019-03-06',30],['2019-03-07',32],['2019-03-08',19],['2019-03-09',7],['2019-03-10',11],['2019-03-11',39],['2019-03-12',36],['2019-03-13',30],['2019-03-14',28],['2019-03-15',23],['2019-03-16',19],['2019-03-17',16],['2019-03-18',28],['2019-03-19',29],['2019-03-20',28],['2019-03-21',28],['2019-03-22',22],['2019-03-23',16],['2019-03-24',21],['2019-03-25',30],['2019-03-26',35],['2019-03-27',30],['2019-03-28',22],['2019-03-29',17],['2019-03-30',7],['2019-03-31',14],['2019-04-01',26],['2019-04-02',30],['2019-04-03',26],['2019-04-04',27],['2019-04-05',24],['2019-04-06',5],['2019-04-07',15],['2019-04-08',30],['2019-04-09',32],['2019-04-10',35],['2019-04-11',36],['2019-04-12',28],['2019-04-13',6],['2019-04-14',21],['2019-04-15',33],['2019-04-16',32],['2019-04-17',30],['2019-04-18',31],['2019-04-19',16],['2019-04-20',4],['2019-04-21',3],['2019-04-22',35],['2019-04-23',34],['2019-04-24',24],['2019-04-25',28],['2019-04-26',27],['2019-04-27',4],['2019-04-28',15],['2019-04-29',27],['2019-04-30',29],['2019-05-01',26],['2019-05-02',29],['2019-05-03',27],['2019-05-04',27],['2019-05-05',35],['2019-05-06',44],['2019-05-07',49],['2019-05-08',48],['2019-05-09',43],['2019-05-10',29],['2019-05-11',11],['2019-05-12',16],['2019-05-13',25],['2019-05-14',26],['2019-05-15',23],['2019-05-16',28],['2019-05-17',28],['2019-05-18',8],['2019-05-19',16],['2019-05-20',29],['2019-05-21',28],['2019-05-22',25],['2019-05-23',29],['2019-05-24',25],['2019-05-25',3],['2019-05-26',19],['2019-05-27',16],['2019-05-28',38],['2019-05-29',37],['2019-05-30',32],['2019-05-31',26],['2019-06-01',11],['2019-06-02',21],['2019-06-03',31],['2019-06-04',36],['2019-06-05',32],['2019-06-06',35],['2019-06-07',36],['2019-06-08',15],['2019-06-09',15],['2019-06-10',36],['2019-06-11',42],['2019-06-12',38],['2019-06-13',37],['2019-06-14',25],['2019-06-15',5],['2019-06-16',15],['2019-06-17',31],['2019-06-18',30],['2019-06-19',122],['2019-06-20',68],['2019-06-21',41],['2019-06-22',28],['2019-06-23',32],['2019-06-24',51],['2019-06-25',41],['2019-06-26',38],['2019-06-27',127],['2019-06-28',167],['2019-06-29',107],['2019-06-30',113],['2019-07-01',88],['2019-07-02',63],['2019-07-03',70],['2019-07-04',66],['2019-07-05',60],['2019-07-06',37],['2019-07-07',45],['2019-07-08',40],['2019-07-09',43],['2019-07-10',42],['2019-07-11',56],['2019-07-12',38],['2019-07-13',32],['2019-07-14',27],['2019-07-15',49],['2019-07-16',200],['2019-07-17',166],['2019-07-18',174],['2019-07-19',160],['2019-07-20',212],['2019-07-21',153],['2019-07-22',120],['2019-07-23',92],['2019-07-24',80],['2019-07-25',97],['2019-07-26',88],['2019-07-27',71],['2019-07-28',79],['2019-07-29',67],['2019-07-30',63],['2019-07-31',62],['2019-08-01',70],['2019-08-02',75],['2019-08-03',67],['2019-08-04',60],['2019-08-05',49],['2019-08-06',56],['2019-08-07',164],['2019-08-08',252],['2019-08-09',282],['2019-08-10',254],['2019-08-11',248],['2019-08-12',97],['2019-08-13',74],['2019-08-14',77],['2019-08-15',68],['2019-08-16',56],['2019-08-17',53],['2019-08-18',64],['2019-08-19',52],['2019-08-20',68],['2019-08-21',68],['2019-08-22',57],['2019-08-23',59],['2019-08-24',57],['2019-08-25',43],['2019-08-26',48],['2019-08-27',81],['2019-08-28',94],['2019-08-29',79],['2019-08-30',55],['2019-08-31',49],['2019-09-01',71],['2019-09-02',55],['2019-09-03',53],['2019-09-04',53],['2019-09-05',185],['2019-09-06',291],['2019-09-07',227],['2019-09-08',193],['2019-09-09',149],['2019-09-10',128],['2019-09-11',156],['2019-09-12',125],['2019-09-13',131],['2019-09-14',107],['2019-09-15',110],['2019-09-16',127],['2019-09-17',83],['2019-09-18',100],['2019-09-19',95],['2019-09-20',134],['2019-09-21',121],['2019-09-22',95],['2019-09-23',99],['2019-09-24',102],['2019-09-25',91],['2019-09-26',87],['2019-09-27',113],['2019-09-28',103],['2019-09-29',87],['2019-09-30',104],['2019-10-01',102],['2019-10-02',114],['2019-10-03',105],['2019-10-04',97],['2019-10-05',77],['2019-10-06',74],['2019-10-07',85],['2019-10-08',80],['2019-10-09',80],['2019-10-10',83],['2019-10-11',108],['2019-10-12',101],['2019-10-13',92],['2019-10-14',95],['2019-10-15',98],['2019-10-16',143],['2019-10-17',215],['2019-10-18',179],['2019-10-19',171],['2019-10-20',173],['2019-10-21',174],['2019-10-22',150],['2019-10-23',139],['2019-10-24',113],['2019-10-25',121],['2019-10-26',122],['2019-10-27',111],['2019-10-28',122],['2019-10-29',129],['2019-10-30',233],['2019-10-31',246],['2019-11-01',339],['2019-11-02',420],['2019-11-03',360],['2019-11-04',294],['2019-11-05',275],['2019-11-06',273],['2019-11-07',348],['2019-11-08',390],['2019-11-09',434],['2019-11-10',454],['2019-11-11',370],['2019-11-12',67],['2019-11-13',48],['2019-11-14',21797],['2019-11-15',20594],['2019-11-16',26163],['2019-11-17',26767],['2019-11-18',19596],['2019-11-19',17971],['2019-11-20',17496],['2019-11-21',16814],['2019-11-22',17379],['2019-11-23',22385],['2019-11-24',23201],['2019-11-25',16796],['2019-11-26',15748],['2019-11-27',15553],['2019-11-28',15583],['2019-11-29',16391],['2019-11-30',20010],['2019-12-01',20315],['2019-12-02',15120],['2019-12-03',14207],['2019-12-04',13556],['2019-12-05',13329],['2019-12-06',14002],['2019-12-07',18413],['2019-12-08',18893],['2019-12-09',14361],['2019-12-10',13507],['2019-12-11',12669],['2019-12-12',12599],['2019-12-13',12842],['2019-12-14',16528],['2019-12-15',17187],['2019-12-16',13497],['2019-12-17',12987],['2019-12-18',12538],['2019-12-19',13140],['2019-12-20',13673],['2019-12-21',16574],['2019-12-22',17512],['2019-12-23',15182],['2019-12-24',15226],['2019-12-25',15318],['2019-12-26',15949],['2019-12-27',17080],['2019-12-28',18555],['2019-12-29',18749],['2019-12-30',17517],['2019-12-31',16773],['2020-01-01',18128],['2020-01-02',16780],['2020-01-03',17131],['2020-01-04',19131],['2020-01-05',18753],['2020-01-06',14837],['2020-01-07',14083],['2020-01-08',13636],['2020-01-09',14466],['2020-01-10',14837],['2020-01-11',17580],['2020-01-12',18262],['2020-01-13',14365],['2020-01-14',14017],['2020-01-15',13439],['2020-01-16',13368],['2020-01-17',14352],['2020-01-18',16666],['2020-01-19',17765],['2020-01-20',15138],['2020-01-21',13650],['2020-01-22',13878],['2020-01-23',13607],['2020-01-24',14790],['2020-01-25',18542],['2020-01-26',21513],['2020-01-27',16510],['2020-01-28',15546],['2020-01-29',14386],['2020-01-30',13865],['2020-01-31',15228],['2020-02-01',19386],['2020-02-02',20566],['2020-02-03',14739],['2020-02-04',13977],['2020-02-05',13501],['2020-02-06',13376],['2020-02-07',14526],['2020-02-08',19080],['2020-02-09',20924],['2020-02-10',14681],['2020-02-11',14147],['2020-02-12',13494],['2020-02-13',13093],['2020-02-14',13656],['2020-02-15',18519],['2020-02-16',19191]],[['2019-02-18',39],['2019-02-19',69],['2019-02-20',69],['2019-02-21',69],['2019-02-22',60],['2019-02-23',19],['2019-02-24',24],['2019-02-25',61],['2019-02-26',62],['2019-02-27',66],['2019-02-28',64],['2019-03-01',52],['2019-03-02',7],['2019-03-03',17],['2019-03-04',53],['2019-03-05',45],['2019-03-06',50],['2019-03-07',58],['2019-03-08',58],['2019-03-09',26],['2019-03-10',10],['2019-03-11',62],['2019-03-12',70],['2019-03-13',67],['2019-03-14',56],['2019-03-15',88],['2019-03-16',84],['2019-03-17',69],['2019-03-18',88],['2019-03-19',98],['2019-03-20',79],['2019-03-21',85],['2019-03-22',90],['2019-03-23',46],['2019-03-24',37],['2019-03-25',83],['2019-03-26',66],['2019-03-27',73],['2019-03-28',63],['2019-03-29',56],['2019-03-30',12],['2019-03-31',18],['2019-04-01',53],['2019-04-02',60],['2019-04-03',52],['2019-04-04',46],['2019-04-05',47],['2019-04-06',14],['2019-04-07',11],['2019-04-08',53],['2019-04-09',58],['2019-04-10',55],['2019-04-11',56],['2019-04-12',51],['2019-04-13',17],['2019-04-14',11],['2019-04-15',50],['2019-04-16',66],['2019-04-17',60],['2019-04-18',55],['2019-04-19',37],['2019-04-20',20],['2019-04-21',4],['2019-04-22',36],['2019-04-23',57],['2019-04-24',55],['2019-04-25',38],['2019-04-26',42],['2019-04-27',4],['2019-04-28',7],['2019-04-29',38],['2019-04-30',45],['2019-05-01',71],['2019-05-02',59],['2019-05-03',59],['2019-05-04',18],['2019-05-05',28],['2019-05-06',49],['2019-05-07',52],['2019-05-08',60],['2019-05-09',57],['2019-05-10',56],['2019-05-11',19],['2019-05-12',11],['2019-05-13',50],['2019-05-14',54],['2019-05-15',54],['2019-05-16',60],['2019-05-17',54],['2019-05-18',12],['2019-05-19',8],['2019-05-20',50],['2019-05-21',53],['2019-05-22',55],['2019-05-23',64],['2019-05-24',61],['2019-05-25',25],['2019-05-26',13],['2019-05-27',33],['2019-05-28',82],['2019-05-29',91],['2019-05-30',77],['2019-05-31',60],['2019-06-01',22],['2019-06-02',17],['2019-06-03',70],['2019-06-04',73],['2019-06-05',70],['2019-06-06',59],['2019-06-07',73],['2019-06-08',38],['2019-06-09',17],['2019-06-10',50],['2019-06-11',67],['2019-06-12',66],['2019-06-13',66],['2019-06-14',65],['2019-06-15',29],['2019-06-16',20],['2019-06-17',67],['2019-06-18',64],['2019-06-19',434],['2019-06-20',674],['2019-06-21',450],['2019-06-22',387],['2019-06-23',288],['2019-06-24',272],['2019-06-25',283],['2019-06-26',246],['2019-06-27',239],['2019-06-28',2029],['2019-06-29',1531],['2019-06-30',1182],['2019-07-01',877],['2019-07-02',740],['2019-07-03',717],['2019-07-04',638],['2019-07-05',496],['2019-07-06',511],['2019-07-07',482],['2019-07-08',423],['2019-07-09',391],['2019-07-10',361],['2019-07-11',420],['2019-07-12',486],['2019-07-13',410],['2019-07-14',318],['2019-07-15',306],['2019-07-16',1127],['2019-07-17',2297],['2019-07-18',1693],['2019-07-19',2153],['2019-07-20',2900],['2019-07-21',1993],['2019-07-22',1511],['2019-07-23',1286],['2019-07-24',1184],['2019-07-25',1182],['2019-07-26',1177],['2019-07-27',1072],['2019-07-28',949],['2019-07-29',765],['2019-07-30',715],['2019-07-31',721],['2019-08-01',720],['2019-08-02',983],['2019-08-03',997],['2019-08-04',811],['2019-08-05',690],['2019-08-06',630],['2019-08-07',1493],['2019-08-08',2557],['2019-08-09',3317],['2019-08-10',2635],['2019-08-11',2197],['2019-08-12',1556],['2019-08-13',1074],['2019-08-14',868],['2019-08-15',968],['2019-08-16',855],['2019-08-17',862],['2019-08-18',800],['2019-08-19',776],['2019-08-20',805],['2019-08-21',674],['2019-08-22',672],['2019-08-23',673],['2019-08-24',660],['2019-08-25',612],['2019-08-26',461],['2019-08-27',706],['2019-08-28',1239],['2019-08-29',772],['2019-08-30',677],['2019-08-31',746],['2019-09-01',670],['2019-09-02',547],['2019-09-03',501],['2019-09-04',484],['2019-09-05',802],['2019-09-06',3429],['2019-09-07',2974],['2019-09-08',2273],['2019-09-09',1585],['2019-09-10',1374],['2019-09-11',1512],['2019-09-12',1216],['2019-09-13',1276],['2019-09-14',1556],['2019-09-15',1313],['2019-09-16',1074],['2019-09-17',978],['2019-09-18',895],['2019-09-19',853],['2019-09-20',1476],['2019-09-21',1914],['2019-09-22',1385],['2019-09-23',1038],['2019-09-24',952],['2019-09-25',865],['2019-09-26',837],['2019-09-27',1253],['2019-09-28',1596],['2019-09-29',1151],['2019-09-30',955],['2019-10-01',1011],['2019-10-02',828],['2019-10-03',840],['2019-10-04',824],['2019-10-05',801],['2019-10-06',743],['2019-10-07',642],['2019-10-08',613],['2019-10-09',600],['2019-10-10',674],['2019-10-11',1230],['2019-10-12',1579],['2019-10-13',1112],['2019-10-14',865],['2019-10-15',865],['2019-10-16',998],['2019-10-17',2298],['2019-10-18',2351],['2019-10-19',2273],['2019-10-20',1823],['2019-10-21',1498],['2019-10-22',1383],['2019-10-23',1235],['2019-10-24',1121],['2019-10-25',1078],['2019-10-26',1557],['2019-10-27',1309],['2019-10-28',1055],['2019-10-29',1066],['2019-10-30',1806],['2019-10-31',2874],['2019-11-01',2790],['2019-11-02',3890],['2019-11-03',3285],['2019-11-04',2401],['2019-11-05',2327],['2019-11-06',2151],['2019-11-07',3262],['2019-11-08',3078],['2019-11-09',3690],['2019-11-10',3443],['2019-11-11',2458],['2019-11-12',251],['2019-11-13',189],['2019-11-14',87740],['2019-11-15',150768],['2019-11-16',156701],['2019-11-17',157231],['2019-11-18',126351],['2019-11-19',119994],['2019-11-20',117682],['2019-11-21',112477],['2019-11-22',115850],['2019-11-23',134639],['2019-11-24',139747],['2019-11-25',107884],['2019-11-26',106623],['2019-11-27',104459],['2019-11-28',103000],['2019-11-29',104391],['2019-11-30',121904],['2019-12-01',127855],['2019-12-02',100161],['2019-12-03',95283],['2019-12-04',90511],['2019-12-05',89266],['2019-12-06',92368],['2019-12-07',107838],['2019-12-08',114832],['2019-12-09',91524],['2019-12-10',87120],['2019-12-11',84438],['2019-12-12',82551],['2019-12-13',84522],['2019-12-14',98574],['2019-12-15',104069],['2019-12-16',84518],['2019-12-17',84277],['2019-12-18',87386],['2019-12-19',85482],['2019-12-20',87617],['2019-12-21',98574],['2019-12-22',104993],['2019-12-23',95928],['2019-12-24',90925],['2019-12-25',89104],['2019-12-26',96088],['2019-12-27',99387],['2019-12-28',105741],['2019-12-29',110093],['2019-12-30',101027],['2019-12-31',93747],['2020-01-01',99556],['2020-01-02',97742],['2020-01-03',98756],['2020-01-04',107851],['2020-01-05',109279],['2020-01-06',89815],['2020-01-07',83166],['2020-01-08',82225],['2020-01-09',83871],['2020-01-10',85831],['2020-01-11',100665],['2020-01-12',105059],['2020-01-13',82918],['2020-01-14',79973],['2020-01-15',78661],['2020-01-16',77721],['2020-01-17',81342],['2020-01-18',96219],['2020-01-19',99335],['2020-01-20',81454],['2020-01-21',79597],['2020-01-22',81523],['2020-01-23',82231],['2020-01-24',91734],['2020-01-25',111038],['2020-01-26',121034],['2020-01-27',104488],['2020-01-28',97650],['2020-01-29',93298],['2020-01-30',89784],['2020-01-31',94882],['2020-02-01',109628],['2020-02-02',114769],['2020-02-03',90262],['2020-02-04',88580],['2020-02-05',87972],['2020-02-06',87637],['2020-02-07',92375],['2020-02-08',108257],['2020-02-09',115316],['2020-02-10',90461],['2020-02-11',88754],['2020-02-12',86682],['2020-02-13',85726],['2020-02-14',85822],['2020-02-15',99929],['2020-02-16',107185]] ]
, {
animate: true,
animateReplot: true,
cursor: {
show: true,
zoom: true,
looseZoom: true,
clickReset: true,
showTooltip: false,
showTooltipUnitPosition: false
},
series:[ { label: 'Peak Concurrent Users'
, color: '#038080'
, highlighter: { formatString: 'Peak Concurrent Users: %s, %s'} , pointLabels: {
show: false,
markerOptions: { style: 'diamond' }, ypadding: 1,
}
, yaxis: 'yaxis'
, renderer: $J.jqplot.LineRenderer
, showHighlight: true , rendererOptions: {
animation: { speed: 2000 }
, highlightMouseOver: true
}
},
{ label: 'Daily Active Users'
, color: '#8a5706'
, highlighter: { formatString: 'Daily Active Users: %s, %s'} , pointLabels: {
show: false,
markerOptions: { style: 'diamond' }, ypadding: 1,
}
, yaxis: 'yaxis'
, renderer: $J.jqplot.LineRenderer
, showHighlight: true , rendererOptions: {
animation: { speed: 2000 }
, highlightMouseOver: true
}
},
],
seriesDefaults: {
showMarker: false,
lineWidth: 1.5 },
grid: {
backgroundColor: '#242424',
gridLineColor: '#424242',
borderColor: '#424242'
},
rendererOptions: {
showDataLabels: true
},
AxesDefaults: { pad: 0 },
axes: {
xaxis: {
renderer: $J.jqplot.DateAxisRenderer,
rendererOptions:{ tickRenderer: $J.jqplot.CanvasAxisTickRenderer },
numberTicks: 5,
tickOptions: {
formatString: '%b-%d-%Y', fontSize: '10pt'
},
min: '2019-01-30', max: '2020-03-06', drawMajorGridlines: true,
drawMinorGridlines: true,
drawMajorTickMarks: true,
rendererOptions: {
tickInset: 0.5,
minorTicks: 1,
sortMergedLabels: true
}
},
yaxis: { renderer: $J.jqplot.LinearAxisRenderer, rendererOptions: { forceTickAt0: true },labelRenderer: $J.jqplot.CanvasAxisLabelRenderer, label: '',min: 0, tickRenderer: $J.jqplot.CanvasAxisTickRenderer, tickOptions: { formatString: "%'i",fontSize: '10pt', showGridline: true }, pad: 1.01 } },
highlighter: {
show: true,
showLabel: true,
tooltipAxes: 'xy',
sizeAdjust: 2 ,
tooltipLocation : 'n',
tooltipOffset: 10,
lineWidthAdjust: 3,
useAxesFormatters: true
},
legend: {
renderer: $J.jqplot.EnhancedLegendRenderer
, show: true
, placement: 'outsideGrid'
, location: 's'
, fontSize: '10pt'
, marginBottom: '10px'
, rendererOptions: {
numberColumns: null,
numberRows: 1
}
},
});
});
</script>
You can try using string functions such as strip(), slice(), split() to clean out the data from the json block then run a python iterator to read and write data to a new csv file.
You have it as string so you can use standard functions for strings: split(), strip(), slicing [start:end], etc.
BTW: I use eval() or module dirtyjson to convert it because standard json makes problem beacuse string is not correct JSON data.
text = '''<script> ... </script>'''
lines = text.splitlines() # create list of lines
line = lines[10] # get one line
line = line[14:] # remove some chars
data = eval(line) # convert to list
#import json
#data = json.loads(line) # ERROR
#import dirtyjson
#data = dirtyjson.loads(line) # WORKS
print(data[0][0])
print(data[1][0])
Results
['2019-02-18', 27]
['2019-02-18', 39]
You have two lists data[0] and data[0] with values
['2019-02-18', 27] # from first list
['2019-02-18', 39] # from second list
which you can convert to
['2019-02-18', 27, 39]
and later to DataFrame using
import pandas as pd
new_data = []
for a, b in zip(data[0], data[1]):
if a[0] != b[0]:
print('Error', a, b)
else:
new_data.append([a[0], a[1], b[1]])
df = pd.DataFrame(new_data)
print(df)
Result:
0 1 2
0 2019-02-18 27 39
1 2019-02-19 42 69
2 2019-02-20 39 69
3 2019-02-21 40 69
4 2019-02-22 37 60
.. ... ... ...
359 2020-02-12 13494 86682
360 2020-02-13 13093 85726
361 2020-02-14 13656 85822
362 2020-02-15 18519 99929
363 2020-02-16 19191 107185
[364 rows x 3 columns]
Full working code:
text = '''<script>
var plotActions = null;
$J(document).ready( function() {
$J.jqplot.config.enablePlugins = true;
plotActions = $J.jqplot(
'actions_graph'
, [ [['2019-02-18',27],['2019-02-19',42],['2019-02-20',39],['2019-02-21',40],['2019-02-22',37],['2019-02-23',11],['2019-02-24',28],['2019-02-25',37],['2019-02-26',36],['2019-02-27',39],['2019-02-28',36],['2019-03-01',27],['2019-03-02',13],['2019-03-03',24],['2019-03-04',27],['2019-03-05',27],['2019-03-06',30],['2019-03-07',32],['2019-03-08',19],['2019-03-09',7],['2019-03-10',11],['2019-03-11',39],['2019-03-12',36],['2019-03-13',30],['2019-03-14',28],['2019-03-15',23],['2019-03-16',19],['2019-03-17',16],['2019-03-18',28],['2019-03-19',29],['2019-03-20',28],['2019-03-21',28],['2019-03-22',22],['2019-03-23',16],['2019-03-24',21],['2019-03-25',30],['2019-03-26',35],['2019-03-27',30],['2019-03-28',22],['2019-03-29',17],['2019-03-30',7],['2019-03-31',14],['2019-04-01',26],['2019-04-02',30],['2019-04-03',26],['2019-04-04',27],['2019-04-05',24],['2019-04-06',5],['2019-04-07',15],['2019-04-08',30],['2019-04-09',32],['2019-04-10',35],['2019-04-11',36],['2019-04-12',28],['2019-04-13',6],['2019-04-14',21],['2019-04-15',33],['2019-04-16',32],['2019-04-17',30],['2019-04-18',31],['2019-04-19',16],['2019-04-20',4],['2019-04-21',3],['2019-04-22',35],['2019-04-23',34],['2019-04-24',24],['2019-04-25',28],['2019-04-26',27],['2019-04-27',4],['2019-04-28',15],['2019-04-29',27],['2019-04-30',29],['2019-05-01',26],['2019-05-02',29],['2019-05-03',27],['2019-05-04',27],['2019-05-05',35],['2019-05-06',44],['2019-05-07',49],['2019-05-08',48],['2019-05-09',43],['2019-05-10',29],['2019-05-11',11],['2019-05-12',16],['2019-05-13',25],['2019-05-14',26],['2019-05-15',23],['2019-05-16',28],['2019-05-17',28],['2019-05-18',8],['2019-05-19',16],['2019-05-20',29],['2019-05-21',28],['2019-05-22',25],['2019-05-23',29],['2019-05-24',25],['2019-05-25',3],['2019-05-26',19],['2019-05-27',16],['2019-05-28',38],['2019-05-29',37],['2019-05-30',32],['2019-05-31',26],['2019-06-01',11],['2019-06-02',21],['2019-06-03',31],['2019-06-04',36],['2019-06-05',32],['2019-06-06',35],['2019-06-07',36],['2019-06-08',15],['2019-06-09',15],['2019-06-10',36],['2019-06-11',42],['2019-06-12',38],['2019-06-13',37],['2019-06-14',25],['2019-06-15',5],['2019-06-16',15],['2019-06-17',31],['2019-06-18',30],['2019-06-19',122],['2019-06-20',68],['2019-06-21',41],['2019-06-22',28],['2019-06-23',32],['2019-06-24',51],['2019-06-25',41],['2019-06-26',38],['2019-06-27',127],['2019-06-28',167],['2019-06-29',107],['2019-06-30',113],['2019-07-01',88],['2019-07-02',63],['2019-07-03',70],['2019-07-04',66],['2019-07-05',60],['2019-07-06',37],['2019-07-07',45],['2019-07-08',40],['2019-07-09',43],['2019-07-10',42],['2019-07-11',56],['2019-07-12',38],['2019-07-13',32],['2019-07-14',27],['2019-07-15',49],['2019-07-16',200],['2019-07-17',166],['2019-07-18',174],['2019-07-19',160],['2019-07-20',212],['2019-07-21',153],['2019-07-22',120],['2019-07-23',92],['2019-07-24',80],['2019-07-25',97],['2019-07-26',88],['2019-07-27',71],['2019-07-28',79],['2019-07-29',67],['2019-07-30',63],['2019-07-31',62],['2019-08-01',70],['2019-08-02',75],['2019-08-03',67],['2019-08-04',60],['2019-08-05',49],['2019-08-06',56],['2019-08-07',164],['2019-08-08',252],['2019-08-09',282],['2019-08-10',254],['2019-08-11',248],['2019-08-12',97],['2019-08-13',74],['2019-08-14',77],['2019-08-15',68],['2019-08-16',56],['2019-08-17',53],['2019-08-18',64],['2019-08-19',52],['2019-08-20',68],['2019-08-21',68],['2019-08-22',57],['2019-08-23',59],['2019-08-24',57],['2019-08-25',43],['2019-08-26',48],['2019-08-27',81],['2019-08-28',94],['2019-08-29',79],['2019-08-30',55],['2019-08-31',49],['2019-09-01',71],['2019-09-02',55],['2019-09-03',53],['2019-09-04',53],['2019-09-05',185],['2019-09-06',291],['2019-09-07',227],['2019-09-08',193],['2019-09-09',149],['2019-09-10',128],['2019-09-11',156],['2019-09-12',125],['2019-09-13',131],['2019-09-14',107],['2019-09-15',110],['2019-09-16',127],['2019-09-17',83],['2019-09-18',100],['2019-09-19',95],['2019-09-20',134],['2019-09-21',121],['2019-09-22',95],['2019-09-23',99],['2019-09-24',102],['2019-09-25',91],['2019-09-26',87],['2019-09-27',113],['2019-09-28',103],['2019-09-29',87],['2019-09-30',104],['2019-10-01',102],['2019-10-02',114],['2019-10-03',105],['2019-10-04',97],['2019-10-05',77],['2019-10-06',74],['2019-10-07',85],['2019-10-08',80],['2019-10-09',80],['2019-10-10',83],['2019-10-11',108],['2019-10-12',101],['2019-10-13',92],['2019-10-14',95],['2019-10-15',98],['2019-10-16',143],['2019-10-17',215],['2019-10-18',179],['2019-10-19',171],['2019-10-20',173],['2019-10-21',174],['2019-10-22',150],['2019-10-23',139],['2019-10-24',113],['2019-10-25',121],['2019-10-26',122],['2019-10-27',111],['2019-10-28',122],['2019-10-29',129],['2019-10-30',233],['2019-10-31',246],['2019-11-01',339],['2019-11-02',420],['2019-11-03',360],['2019-11-04',294],['2019-11-05',275],['2019-11-06',273],['2019-11-07',348],['2019-11-08',390],['2019-11-09',434],['2019-11-10',454],['2019-11-11',370],['2019-11-12',67],['2019-11-13',48],['2019-11-14',21797],['2019-11-15',20594],['2019-11-16',26163],['2019-11-17',26767],['2019-11-18',19596],['2019-11-19',17971],['2019-11-20',17496],['2019-11-21',16814],['2019-11-22',17379],['2019-11-23',22385],['2019-11-24',23201],['2019-11-25',16796],['2019-11-26',15748],['2019-11-27',15553],['2019-11-28',15583],['2019-11-29',16391],['2019-11-30',20010],['2019-12-01',20315],['2019-12-02',15120],['2019-12-03',14207],['2019-12-04',13556],['2019-12-05',13329],['2019-12-06',14002],['2019-12-07',18413],['2019-12-08',18893],['2019-12-09',14361],['2019-12-10',13507],['2019-12-11',12669],['2019-12-12',12599],['2019-12-13',12842],['2019-12-14',16528],['2019-12-15',17187],['2019-12-16',13497],['2019-12-17',12987],['2019-12-18',12538],['2019-12-19',13140],['2019-12-20',13673],['2019-12-21',16574],['2019-12-22',17512],['2019-12-23',15182],['2019-12-24',15226],['2019-12-25',15318],['2019-12-26',15949],['2019-12-27',17080],['2019-12-28',18555],['2019-12-29',18749],['2019-12-30',17517],['2019-12-31',16773],['2020-01-01',18128],['2020-01-02',16780],['2020-01-03',17131],['2020-01-04',19131],['2020-01-05',18753],['2020-01-06',14837],['2020-01-07',14083],['2020-01-08',13636],['2020-01-09',14466],['2020-01-10',14837],['2020-01-11',17580],['2020-01-12',18262],['2020-01-13',14365],['2020-01-14',14017],['2020-01-15',13439],['2020-01-16',13368],['2020-01-17',14352],['2020-01-18',16666],['2020-01-19',17765],['2020-01-20',15138],['2020-01-21',13650],['2020-01-22',13878],['2020-01-23',13607],['2020-01-24',14790],['2020-01-25',18542],['2020-01-26',21513],['2020-01-27',16510],['2020-01-28',15546],['2020-01-29',14386],['2020-01-30',13865],['2020-01-31',15228],['2020-02-01',19386],['2020-02-02',20566],['2020-02-03',14739],['2020-02-04',13977],['2020-02-05',13501],['2020-02-06',13376],['2020-02-07',14526],['2020-02-08',19080],['2020-02-09',20924],['2020-02-10',14681],['2020-02-11',14147],['2020-02-12',13494],['2020-02-13',13093],['2020-02-14',13656],['2020-02-15',18519],['2020-02-16',19191]],[['2019-02-18',39],['2019-02-19',69],['2019-02-20',69],['2019-02-21',69],['2019-02-22',60],['2019-02-23',19],['2019-02-24',24],['2019-02-25',61],['2019-02-26',62],['2019-02-27',66],['2019-02-28',64],['2019-03-01',52],['2019-03-02',7],['2019-03-03',17],['2019-03-04',53],['2019-03-05',45],['2019-03-06',50],['2019-03-07',58],['2019-03-08',58],['2019-03-09',26],['2019-03-10',10],['2019-03-11',62],['2019-03-12',70],['2019-03-13',67],['2019-03-14',56],['2019-03-15',88],['2019-03-16',84],['2019-03-17',69],['2019-03-18',88],['2019-03-19',98],['2019-03-20',79],['2019-03-21',85],['2019-03-22',90],['2019-03-23',46],['2019-03-24',37],['2019-03-25',83],['2019-03-26',66],['2019-03-27',73],['2019-03-28',63],['2019-03-29',56],['2019-03-30',12],['2019-03-31',18],['2019-04-01',53],['2019-04-02',60],['2019-04-03',52],['2019-04-04',46],['2019-04-05',47],['2019-04-06',14],['2019-04-07',11],['2019-04-08',53],['2019-04-09',58],['2019-04-10',55],['2019-04-11',56],['2019-04-12',51],['2019-04-13',17],['2019-04-14',11],['2019-04-15',50],['2019-04-16',66],['2019-04-17',60],['2019-04-18',55],['2019-04-19',37],['2019-04-20',20],['2019-04-21',4],['2019-04-22',36],['2019-04-23',57],['2019-04-24',55],['2019-04-25',38],['2019-04-26',42],['2019-04-27',4],['2019-04-28',7],['2019-04-29',38],['2019-04-30',45],['2019-05-01',71],['2019-05-02',59],['2019-05-03',59],['2019-05-04',18],['2019-05-05',28],['2019-05-06',49],['2019-05-07',52],['2019-05-08',60],['2019-05-09',57],['2019-05-10',56],['2019-05-11',19],['2019-05-12',11],['2019-05-13',50],['2019-05-14',54],['2019-05-15',54],['2019-05-16',60],['2019-05-17',54],['2019-05-18',12],['2019-05-19',8],['2019-05-20',50],['2019-05-21',53],['2019-05-22',55],['2019-05-23',64],['2019-05-24',61],['2019-05-25',25],['2019-05-26',13],['2019-05-27',33],['2019-05-28',82],['2019-05-29',91],['2019-05-30',77],['2019-05-31',60],['2019-06-01',22],['2019-06-02',17],['2019-06-03',70],['2019-06-04',73],['2019-06-05',70],['2019-06-06',59],['2019-06-07',73],['2019-06-08',38],['2019-06-09',17],['2019-06-10',50],['2019-06-11',67],['2019-06-12',66],['2019-06-13',66],['2019-06-14',65],['2019-06-15',29],['2019-06-16',20],['2019-06-17',67],['2019-06-18',64],['2019-06-19',434],['2019-06-20',674],['2019-06-21',450],['2019-06-22',387],['2019-06-23',288],['2019-06-24',272],['2019-06-25',283],['2019-06-26',246],['2019-06-27',239],['2019-06-28',2029],['2019-06-29',1531],['2019-06-30',1182],['2019-07-01',877],['2019-07-02',740],['2019-07-03',717],['2019-07-04',638],['2019-07-05',496],['2019-07-06',511],['2019-07-07',482],['2019-07-08',423],['2019-07-09',391],['2019-07-10',361],['2019-07-11',420],['2019-07-12',486],['2019-07-13',410],['2019-07-14',318],['2019-07-15',306],['2019-07-16',1127],['2019-07-17',2297],['2019-07-18',1693],['2019-07-19',2153],['2019-07-20',2900],['2019-07-21',1993],['2019-07-22',1511],['2019-07-23',1286],['2019-07-24',1184],['2019-07-25',1182],['2019-07-26',1177],['2019-07-27',1072],['2019-07-28',949],['2019-07-29',765],['2019-07-30',715],['2019-07-31',721],['2019-08-01',720],['2019-08-02',983],['2019-08-03',997],['2019-08-04',811],['2019-08-05',690],['2019-08-06',630],['2019-08-07',1493],['2019-08-08',2557],['2019-08-09',3317],['2019-08-10',2635],['2019-08-11',2197],['2019-08-12',1556],['2019-08-13',1074],['2019-08-14',868],['2019-08-15',968],['2019-08-16',855],['2019-08-17',862],['2019-08-18',800],['2019-08-19',776],['2019-08-20',805],['2019-08-21',674],['2019-08-22',672],['2019-08-23',673],['2019-08-24',660],['2019-08-25',612],['2019-08-26',461],['2019-08-27',706],['2019-08-28',1239],['2019-08-29',772],['2019-08-30',677],['2019-08-31',746],['2019-09-01',670],['2019-09-02',547],['2019-09-03',501],['2019-09-04',484],['2019-09-05',802],['2019-09-06',3429],['2019-09-07',2974],['2019-09-08',2273],['2019-09-09',1585],['2019-09-10',1374],['2019-09-11',1512],['2019-09-12',1216],['2019-09-13',1276],['2019-09-14',1556],['2019-09-15',1313],['2019-09-16',1074],['2019-09-17',978],['2019-09-18',895],['2019-09-19',853],['2019-09-20',1476],['2019-09-21',1914],['2019-09-22',1385],['2019-09-23',1038],['2019-09-24',952],['2019-09-25',865],['2019-09-26',837],['2019-09-27',1253],['2019-09-28',1596],['2019-09-29',1151],['2019-09-30',955],['2019-10-01',1011],['2019-10-02',828],['2019-10-03',840],['2019-10-04',824],['2019-10-05',801],['2019-10-06',743],['2019-10-07',642],['2019-10-08',613],['2019-10-09',600],['2019-10-10',674],['2019-10-11',1230],['2019-10-12',1579],['2019-10-13',1112],['2019-10-14',865],['2019-10-15',865],['2019-10-16',998],['2019-10-17',2298],['2019-10-18',2351],['2019-10-19',2273],['2019-10-20',1823],['2019-10-21',1498],['2019-10-22',1383],['2019-10-23',1235],['2019-10-24',1121],['2019-10-25',1078],['2019-10-26',1557],['2019-10-27',1309],['2019-10-28',1055],['2019-10-29',1066],['2019-10-30',1806],['2019-10-31',2874],['2019-11-01',2790],['2019-11-02',3890],['2019-11-03',3285],['2019-11-04',2401],['2019-11-05',2327],['2019-11-06',2151],['2019-11-07',3262],['2019-11-08',3078],['2019-11-09',3690],['2019-11-10',3443],['2019-11-11',2458],['2019-11-12',251],['2019-11-13',189],['2019-11-14',87740],['2019-11-15',150768],['2019-11-16',156701],['2019-11-17',157231],['2019-11-18',126351],['2019-11-19',119994],['2019-11-20',117682],['2019-11-21',112477],['2019-11-22',115850],['2019-11-23',134639],['2019-11-24',139747],['2019-11-25',107884],['2019-11-26',106623],['2019-11-27',104459],['2019-11-28',103000],['2019-11-29',104391],['2019-11-30',121904],['2019-12-01',127855],['2019-12-02',100161],['2019-12-03',95283],['2019-12-04',90511],['2019-12-05',89266],['2019-12-06',92368],['2019-12-07',107838],['2019-12-08',114832],['2019-12-09',91524],['2019-12-10',87120],['2019-12-11',84438],['2019-12-12',82551],['2019-12-13',84522],['2019-12-14',98574],['2019-12-15',104069],['2019-12-16',84518],['2019-12-17',84277],['2019-12-18',87386],['2019-12-19',85482],['2019-12-20',87617],['2019-12-21',98574],['2019-12-22',104993],['2019-12-23',95928],['2019-12-24',90925],['2019-12-25',89104],['2019-12-26',96088],['2019-12-27',99387],['2019-12-28',105741],['2019-12-29',110093],['2019-12-30',101027],['2019-12-31',93747],['2020-01-01',99556],['2020-01-02',97742],['2020-01-03',98756],['2020-01-04',107851],['2020-01-05',109279],['2020-01-06',89815],['2020-01-07',83166],['2020-01-08',82225],['2020-01-09',83871],['2020-01-10',85831],['2020-01-11',100665],['2020-01-12',105059],['2020-01-13',82918],['2020-01-14',79973],['2020-01-15',78661],['2020-01-16',77721],['2020-01-17',81342],['2020-01-18',96219],['2020-01-19',99335],['2020-01-20',81454],['2020-01-21',79597],['2020-01-22',81523],['2020-01-23',82231],['2020-01-24',91734],['2020-01-25',111038],['2020-01-26',121034],['2020-01-27',104488],['2020-01-28',97650],['2020-01-29',93298],['2020-01-30',89784],['2020-01-31',94882],['2020-02-01',109628],['2020-02-02',114769],['2020-02-03',90262],['2020-02-04',88580],['2020-02-05',87972],['2020-02-06',87637],['2020-02-07',92375],['2020-02-08',108257],['2020-02-09',115316],['2020-02-10',90461],['2020-02-11',88754],['2020-02-12',86682],['2020-02-13',85726],['2020-02-14',85822],['2020-02-15',99929],['2020-02-16',107185]] ]
, {
animate: true,
animateReplot: true,
cursor: {
show: true,
zoom: true,
looseZoom: true,
clickReset: true,
showTooltip: false,
showTooltipUnitPosition: false
},
series:[ { label: 'Peak Concurrent Users'
, color: '#038080'
, highlighter: { formatString: 'Peak Concurrent Users: %s, %s'} , pointLabels: {
show: false,
markerOptions: { style: 'diamond' }, ypadding: 1,
}
, yaxis: 'yaxis'
, renderer: $J.jqplot.LineRenderer
, showHighlight: true , rendererOptions: {
animation: { speed: 2000 }
, highlightMouseOver: true
}
},
{ label: 'Daily Active Users'
, color: '#8a5706'
, highlighter: { formatString: 'Daily Active Users: %s, %s'} , pointLabels: {
show: false,
markerOptions: { style: 'diamond' }, ypadding: 1,
}
, yaxis: 'yaxis'
, renderer: $J.jqplot.LineRenderer
, showHighlight: true , rendererOptions: {
animation: { speed: 2000 }
, highlightMouseOver: true
}
},
],
seriesDefaults: {
showMarker: false,
lineWidth: 1.5 },
grid: {
backgroundColor: '#242424',
gridLineColor: '#424242',
borderColor: '#424242'
},
rendererOptions: {
showDataLabels: true
},
AxesDefaults: { pad: 0 },
axes: {
xaxis: {
renderer: $J.jqplot.DateAxisRenderer,
rendererOptions:{ tickRenderer: $J.jqplot.CanvasAxisTickRenderer },
numberTicks: 5,
tickOptions: {
formatString: '%b-%d-%Y', fontSize: '10pt'
},
min: '2019-01-30', max: '2020-03-06', drawMajorGridlines: true,
drawMinorGridlines: true,
drawMajorTickMarks: true,
rendererOptions: {
tickInset: 0.5,
minorTicks: 1,
sortMergedLabels: true
}
},
yaxis: { renderer: $J.jqplot.LinearAxisRenderer, rendererOptions: { forceTickAt0: true },labelRenderer: $J.jqplot.CanvasAxisLabelRenderer, label: '',min: 0, tickRenderer: $J.jqplot.CanvasAxisTickRenderer, tickOptions: { formatString: "%'i",fontSize: '10pt', showGridline: true }, pad: 1.01 } },
highlighter: {
show: true,
showLabel: true,
tooltipAxes: 'xy',
sizeAdjust: 2 ,
tooltipLocation : 'n',
tooltipOffset: 10,
lineWidthAdjust: 3,
useAxesFormatters: true
},
legend: {
renderer: $J.jqplot.EnhancedLegendRenderer
, show: true
, placement: 'outsideGrid'
, location: 's'
, fontSize: '10pt'
, marginBottom: '10px'
, rendererOptions: {
numberColumns: null,
numberRows: 1
}
},
});
});
</script>'''
lines = text.splitlines() # create list of lines
line = lines[10] # get one line
line = line[14:] # remove some chars
data = eval(line) # convert to list
#import json
#data = json.loads(line) # ERROR
import dirtyjson
data = dirtyjson.loads(line) # WORKS
print(data[0][0])
print(data[1][0])
new_data = []
for a, b in zip(data[0], data[1]):
if a[0] != b[0]:
print('Error', a, b)
else:
new_data.append([a[0], a[1], b[1]])
import pandas as pd
df = pd.DataFrame(new_data)
print(df)