Click here to Skip to main content
15,888,044 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am not able to add dynamic series in High charts from a panda data frame based on CSV file.

Data in the CSV file looks like this.

Installation    Manufacturing   Sales & Distribution    Project Development Other
          43,934           24,916                 11,744        -               12,908 
          52,503           24,064                 17,722        -               5,948 
          57,177           29,742                 16,005        7,988           8,105 
          69,658           29,851                 19,771        12,169          11,248 
          97,031           32,490                 20,185        15,112          8,989 
          119,931          30,282                 24,377        22,452          11,816 
          137,133          38,121                 32,147        34,400          18,274 
          154,175          40,434                 39,387        34,227          18,111 


What I have tried:

import pandas as pd 
import csv
from highcharts import Highchart

FileName = "C:/Users/kumarso/Documents/Pthon/Pthon.csv"
FileName1 = "C:/ExcelP/Highcharts_Test.html"

H = Highchart()


data = pd.read_csv(FileName) 


for i, series in enumerate(data):
    H.add_data_set(series,
                    series_type='line',
                    name= data.columns)

# write out the html
with open(FileName1, "wt") as fh:
    fh.write(H.htmlcontent)



when I am opening the Html file to view the chart it shows no values, legends etc. only an empty chart. The issue I have is how to add the series like this with the headers.

series: [{
        name: 'Installation',
        data: [43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175]
    }, {
        name: 'Manufacturing',
        data: [24916, 24064, 29742, 29851, 32490, 30282, 38121, 40434]
    }, {
        name: 'Sales & Distribution',
        data: [11744, 17722, 16005, 19771, 20185, 24377, 32147, 39387]
    }, {
        name: 'Project Development',
        data: [null, null, 7988, 12169, 15112, 22452, 34400, 34227]
    }, {
        name: 'Other',
        data: [12908, 5948, 8105, 11248, 8989, 11816, 18274, 18111]
    }],
Posted
Updated 27-Sep-19 7:18am
v2
Comments
Richard MacCutchan 27-Sep-19 4:31am    
The data you have shown is not a .csv file, as there are no separators in the text.
Member 10445425 27-Sep-19 4:39am    
Hi Richard, I copied the table from excel to a csv file. when I am using print(data) command in python, it shows me following

Installation Manufacturing Sales & Distribution Project Development Other
0 43934 24916 11744 0 12908
1 52503 24064 17722 0 5948
2 57177 29742 16005 7988 8105
3 69658 29851 19771 12169 11248
4 97031 32490 20185 15112 8989
5 119931 30282 24377 22452 11816
6 137133 38121 32147 34400 18274
7 154175 40434 39387 34227 18111
Richard MacCutchan 27-Sep-19 5:50am    
Well that is still not CSV format. Do you actually understand that CSV stands for Comma Separated Values? Your text will be seen by the csv reader as lines of text each containing a single value.
Member 10445425 27-Sep-19 6:10am    
Now I am confused. I had a file in a notepad, I imported this to excel via comma separator and saved as a CSV file. Currently, data looks like this in CSV file. Do i need to do something with this more to call it as CSV?

Installation Manufacturing Sales & Distribution Project Development Other
43934 24916 11744 0 12908
52503 24064 17722 0 5948
57177 29742 16005 7988 8105
69658 29851 19771 12169 11248
97031 32490 20185 15112 8989
119931 30282 24377 22452 11816
137133 38121 32147 34400 18274
154175 40434 39387 34227 18111

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900