{"id":24320,"date":"2023-10-17T22:14:38","date_gmt":"2023-10-17T22:14:38","guid":{"rendered":"https:\/\/www.highcharts.com\/blog\/?p=24320"},"modified":"2026-01-13T11:37:09","modified_gmt":"2026-01-13T11:37:09","slug":"highcharts-core-python-csvs","status":"publish","type":"post","link":"https:\/\/www.highcharts.com\/blog\/integration\/highcharts-core-python-csvs\/","title":{"rendered":"Using Highcharts Core for Python with CSVs"},"content":{"rendered":"<p>CSV (Comma-Separated Value) is one of the most common formats for exchanging data files &#8211; both large and small. Because of its popularity, the <b>Highcharts for Python Toolkit<\/b> is designed to work seamlessly with it.<\/p>\n<h2>General Approach<\/h2>\n<p>The <b>Highcharts for Python Toolkit<\/b> provides a number of standard methods that are used to interact with CSV files. These methods generally take the form:<\/p>\n<ul>\n<li><code>.from_csv(as_string_or_file)<\/code> This is always a class method which produces one or more instances, with data pulled from the CSV content found in <code>as_string_or_file<\/code>.<\/li>\n<li><code>.from_csv_in_rows(as_string_or_file)<\/code> This is always a class method which produces one instance for every row in the CSV (<code>as_string_or_file<\/code>).<\/li>\n<li><code>.load_from_csv(as_string_or_file)<\/code> This is an instance method which updates an instance with data read from the <code>as_string_or_file<\/code> argument.<\/li>\n<\/ul>\n<p><i><b>Tip<\/b><\/p>\n<p>All three of these standard methods are packaged to have batteries included. This means that for simple use cases, you can simply pass a CSV to the method, and the method wlil attempt to determine the best way to deserialize the CSV into the appropriate <b>Highcharts for Python<\/b> objects.<\/p>\n<p>However, if you find that you need more fine-grained control, the methods provide powerful tools to give you the control you need when you need it.<\/i><\/p>\n<p>These standard methods &#8211; with near-identical syntax &#8211; are available:<\/p>\n<ul>\n<li>On all <code>series<\/code> classes (descended from <code>SeriesBase<\/code>)<\/li>\n<li>On the <code>Chart<\/code> class<\/li>\n<\/ul>\n<h2>Preparing Your CSV Data<\/h3>\n<p>So let\u2019s try a real-world example. Let\u2019s say you\u2019ve got some annual population counts stored in a CSV file named <code>'census-time-series.csv'<\/code> that looks like this:<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2023\/10\/17212217\/table-with-all-population-US-states-from-2011-to-2019.jpg\" alt=\"table with all population US states from 2010 to 2019\" width=\"1160\" height=\"660\" class=\"alignnone size-full wp-image-24322\" srcset=\"https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2023\/10\/17212217\/table-with-all-population-US-states-from-2011-to-2019.jpg 1160w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2023\/10\/17212217\/table-with-all-population-US-states-from-2011-to-2019-560x319.jpg 560w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2023\/10\/17212217\/table-with-all-population-US-states-from-2011-to-2019-760x432.jpg 760w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2023\/10\/17212217\/table-with-all-population-US-states-from-2011-to-2019-768x437.jpg 768w\" sizes=\"auto, (max-width: 1160px) 100vw, 1160px\" \/><\/p>\n<p>The first column contains the names of geographic regions, while each of the subsequent columns contains the population counts for a given year. Now, let\u2019s say we wanted to visualize this data in various ways.<\/p>\n<h2>Creating the Chart: Chart.from_csv()<\/h2>\n<h3>Relying on the Defaults<\/h3>\n<p>The simplest way to create a chart from a CSV file is to call <code>Chart.from_csv()<\/code> like so:<\/p>\n<pre>my_chart = Chart.from_csv('census-time-series.csv',\r\n                          wrapper_character = '\"')\r\nmy_chart.display()<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2023\/10\/17193624\/Line-chart.jpg\" alt=\"Simple line chart with random data\" width=\"1160\" height=\"341\" class=\"alignnone size-full wp-image-24298\" srcset=\"https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2023\/10\/17193624\/Line-chart.jpg 1160w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2023\/10\/17193624\/Line-chart-560x165.jpg 560w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2023\/10\/17193624\/Line-chart-760x223.jpg 760w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2023\/10\/17193624\/Line-chart-768x226.jpg 768w\" sizes=\"auto, (max-width: 1160px) 100vw, 1160px\" \/><\/p>\n<p>As you can see, we haven\u2019t provided any more instructions besides telling it to generate a chart from the file <code>'census-time-series.csv'<\/code>, and to interpret a single quotation mark as a wrapper character. The result is a line chart, with one series for each year, and one point for each region.<\/p>\n<p><i><b>Tip<\/b><\/p>\n<p>Unless instructed otherwise, <b>Highcharts for Python<\/b> will default to using a line chart.<\/i><\/p>\n<h3>Setting the Series Type<\/h3>\n<p>Why don\u2019t we switch it to a bar chart?<\/p>\n<pre>my_chart = Chart.from_csv('census-time-series.csv',\r\n                          series_type = 'bar',\r\n                          wrapper_character = '\"')<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2023\/10\/17194007\/bar-chart-with-random-data.jpg\" alt=\"bar chart with random data\" width=\"1160\" height=\"345\" class=\"alignnone size-full wp-image-24299\" srcset=\"https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2023\/10\/17194007\/bar-chart-with-random-data.jpg 1160w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2023\/10\/17194007\/bar-chart-with-random-data-560x167.jpg 560w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2023\/10\/17194007\/bar-chart-with-random-data-760x226.jpg 760w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2023\/10\/17194007\/bar-chart-with-random-data-768x228.jpg 768w\" sizes=\"auto, (max-width: 1160px) 100vw, 1160px\" \/><\/p>\n<p>Now the result is a little more readable, but still not great: After all, there are more than fifty geographic regions represented for each year, which makes the chart super crowded. Besides, maybe we\u2019re only interested in a specific year: 2019.<\/p>\n<p>Let\u2019s try focusing our chart.<\/p>\n<h3>Basic Property Mapping<\/h3>\n<pre>my_chart = Chart.from_csv('census-time-series.csv',\r\n                          series_type = 'bar',\r\n                          property_column_map = {\r\n                              'x': 'Geographic Area',\r\n                              'y': '2019'\r\n                          })<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2023\/10\/17194236\/bar-chart-with-random-data-using-blue-color.jpg\" alt=\"bar chart with random data using blue color\" width=\"1160\" height=\"341\" class=\"alignnone size-full wp-image-24300\" srcset=\"https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2023\/10\/17194236\/bar-chart-with-random-data-using-blue-color.jpg 1160w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2023\/10\/17194236\/bar-chart-with-random-data-using-blue-color-560x165.jpg 560w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2023\/10\/17194236\/bar-chart-with-random-data-using-blue-color-760x223.jpg 760w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2023\/10\/17194236\/bar-chart-with-random-data-using-blue-color-768x226.jpg 768w\" sizes=\"auto, (max-width: 1160px) 100vw, 1160px\" \/><\/p>\n<p>Much better! We\u2019ve now added a <code>property_column_map<\/code> argument to the <code>.from_csv()<\/code> method call. This argument tells Highcharts for Python how to map columns in your data to properties in the resulting chart. In this case, the keys <code>'x'<\/code> and <code>'y'<\/code> tell <b>Highcharts for Python<\/b> that you want to map the <code>'Geographic Area'<\/code> column to the resulting series\u2019 data points\u2019 <code>.x<\/code>, and to map the <code>'2019'<\/code> column to the .y properties, respectively.<\/p>\n<p>The net result is that my_chart contains one BarSeries whose .data property contains a BarDataCollection instance populated with the data from the <code>'Geographic Area'<\/code> and &#8216;<code>2019'<\/code> columns in <code>census-time-series.csv<\/code>.<\/p>\n<p>But maybe we actually want to compare a couple different years? Let\u2019s try that.<\/p>\n<p><i><b>Tip<\/b><\/p>\n<p>Not all CSV data contains a header row. If your CSV data does not contain a header row, <code>property_column_map<\/code> accepts <code>int<\/code> values, which indicate the index of the column that you want to map. So the method call above would be equivalent to:<\/p>\n<pre>my_chart = Chart.from_csv('census-time-series.csv',\r\n                          series_type = 'bar',\r\n                          property_column_map = {\r\n                              'x': 0,\r\n                              'y': 10\r\n                          })<\/pre>\n<p><\/i><\/p>\n<h3>Property Mapping with Multiple Series<\/h3>\n<pre>my_chart = Chart.from_csv('census-time-series.csv',\r\n                          series_type = 'column',\r\n                          property_column_map = {\r\n                              'x': 'Geographic Area',\r\n                              'y': ['2017', '2018', '2019']\r\n                          })<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2023\/10\/17194838\/Column-chart-with-random-data-using-blue-color.jpg\" alt=\"Column chart with random data using blue color\" width=\"1160\" height=\"341\" class=\"alignnone size-full wp-image-24302\" srcset=\"https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2023\/10\/17194838\/Column-chart-with-random-data-using-blue-color.jpg 1160w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2023\/10\/17194838\/Column-chart-with-random-data-using-blue-color-560x165.jpg 560w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2023\/10\/17194838\/Column-chart-with-random-data-using-blue-color-760x223.jpg 760w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2023\/10\/17194838\/Column-chart-with-random-data-using-blue-color-768x226.jpg 768w\" sizes=\"auto, (max-width: 1160px) 100vw, 1160px\" \/><\/p>\n<p>Now we\u2019re getting somewhere! We\u2019ve added a list of column names to the <code>'y'<\/code> key in the <code>property_column_map<\/code> argument. Each of those columns has now produced a separate <code>BarSeries<\/code> instance &#8211; but they\u2019re all still sharing the <code>'Geographic Area'<\/code> column as their <code>.x<\/code> value.<\/p>\n<p><i><b>Note<\/b><\/p>\n<p>You can supply multiple values to any property in the <code>property_column_map<\/code>. The example provided above is equivalent to:<\/p>\n<pre>my_chart = Chart.from_csv('census-time-series.csv',\r\n                             series_type = 'column',\r\n                             property_column_map = {\r\n                                 'x': ['Geographic Area', 'Geographic Area', 'Geographic Area'],\r\n                                 'y': ['2017', '2018', '2019']\r\n                             })<\/pre>\n<p>The only catch is that the ultimate number of values for each key must match. If there\u2019s only one value, then it will get repeated for all of the others. But if there\u2019s a mismatch, then <b>Highcharts for Python<\/b> will throw a <code>HighchartsCSVDeserializationError<\/code>.<\/i><\/p>\n<p>But so far, we\u2019ve only been using the <code>'x'<\/code> and <code>'y'<\/code> keys in our <code>property_column_map<\/code>. What if we wanted to configure additional properties? Easy!<\/p>\n<h3>Configuring Additional Properties<\/h3>\n<pre>my_chart = Chart.from_csv('census-time-series.csv',\r\n                          series_type = 'bar',\r\n                          property_column_map = {\r\n                              'x': 'Geographic Area',\r\n                              'y': ['2017', '2018', '2019'],\r\n                              'id': 'some other column'\r\n                          })<\/pre>\n<p>Now, our CSV is pretty simple does not contain a column named &#8220;\u2019some other column\u2019. But *if* it did, then it would use that column to set the :meth:.id <code>&lt;highcharts_core.options.series.data.bar.BarData.id&gt;<\/code>` property of each data point.<\/p>\n<p><i><b>Note<\/b><\/p>\n<p>You can supply any property you want to the <code>property_map<\/code>. If the property is not supported by the series type you\u2019ve selected, then it will be ignored.<\/i><\/p>\n<p>But our chart is still looking a little basic &#8211; why don\u2019t we tweak some series configuration options?<\/p>\n<h3>Configuring Series Options<\/h3>\n<pre>my_chart = Chart.from_csv('census-time-series.csv',\r\n                          series_type = 'bar',\r\n                          property_column_map = {\r\n                              'x': 'Geographic Area',\r\n                              'y': ['2017', '2018', '2019'],\r\n                          },\r\n                          series_kwargs = {\r\n                              'point_padding': 5\r\n                          })<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2023\/10\/17201507\/Column-chart-using-data-from-the-table-above-US-gerographic-population.jpg\" alt=\"Column chart using data from the table above US gerographic population\" width=\"1160\" height=\"342\" class=\"alignnone size-full wp-image-24305\" srcset=\"https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2023\/10\/17201507\/Column-chart-using-data-from-the-table-above-US-gerographic-population.jpg 1160w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2023\/10\/17201507\/Column-chart-using-data-from-the-table-above-US-gerographic-population-560x165.jpg 560w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2023\/10\/17201507\/Column-chart-using-data-from-the-table-above-US-gerographic-population-760x224.jpg 760w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2023\/10\/17201507\/Column-chart-using-data-from-the-table-above-US-gerographic-population-768x226.jpg 768w\" sizes=\"auto, (max-width: 1160px) 100vw, 1160px\" \/><\/p>\n<p>As you can see, we supplied a new <code>series_kwargs<\/code> argument to the <code>.from_csv()<\/code> method call. This argument receives a dict with keys that correspond to properties on the series. In this case, by supplying <code>'point_padding'<\/code> we have set the resulting <code>BarSeries.point_padding<\/code> property to a value of <code>0.25<\/code> &#8211; leading to a bit more spacing between the bars.<\/p>\n<p>But our chart is still a little basic &#8211; why don\u2019t we give it a reasonable title?<\/p>\n<h3>Configuring Options<\/h3>\n<pre>my_chart = Chart.from_csv('census-time-series.csv',\r\n                          series_type = 'bar',\r\n                          wrapper_character = '\"',\r\n                          property_column_map = {\r\n                              'x': 'Geographic Area',\r\n                              'y': ['2017', '2018', '2019']\r\n                          },\r\n                          series_kwargs = {\r\n                              'point_padding': 5\r\n                          },\r\n                          options_kwargs = {\r\n                              'title': {\r\n                                'text': 'This Is My Chart Title'\r\n                              }\r\n                          })<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2023\/10\/17201743\/Column-chart-with-a-title-using-data-from-the-table-above-US-gerographic-population.jpg\" alt=\"Column chart with a title using data from the table above US gerographic population\" width=\"1160\" height=\"352\" class=\"alignnone size-full wp-image-24306\" srcset=\"https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2023\/10\/17201743\/Column-chart-with-a-title-using-data-from-the-table-above-US-gerographic-population.jpg 1160w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2023\/10\/17201743\/Column-chart-with-a-title-using-data-from-the-table-above-US-gerographic-population-560x170.jpg 560w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2023\/10\/17201743\/Column-chart-with-a-title-using-data-from-the-table-above-US-gerographic-population-760x231.jpg 760w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2023\/10\/17201743\/Column-chart-with-a-title-using-data-from-the-table-above-US-gerographic-population-768x233.jpg 768w\" sizes=\"auto, (max-width: 1160px) 100vw, 1160px\" \/><\/p>\n<p>As you can see, we\u2019ve now given our chart a title. We did this by adding a new <ocde>options_kwargs<\/code> argument, which likewise takes a <code>dict<\/code> with keys that correspond to properties on the chart\u2019s <code>HighchartsOptions<\/code> configuration.`<\/p>\n<p>Now let\u2019s say we wanted our chart to render in an HTML <code>&lt;div&gt;<\/code> with an id of <code>'my_target_div<\/code> &#8211; we can configure that in the same method call.<\/p>\n<h3>Configuring Chart Setting<\/h3>\n<pre>my_chart = Chart.from_csv('census-time-series.csv',\r\n                          series_type = 'bar',\r\n                          wrapper_character = '\"',\r\n                          property_column_map = {\r\n                              'x': 'Geographic Area',\r\n                              'y': ['2017', '2018', '2019'],\r\n                          },\r\n                          series_kwargs = {\r\n                              'point_padding': 0.25\r\n                          },\r\n                          options_kwargs = {\r\n                              'title': {\r\n                                'text': 'This Is My Chart Title'\r\n                              }\r\n                          },\r\n                          chart_kwargs = {\r\n                              'container': 'my_target_div'\r\n                          })<\/pre>\n<p>While you can\u2019t really see the difference here, by adding the <code>chart_kwargs<\/code> argument to the method call, we now set the <code>.container<\/code> property on <code>my_chart<\/code>.<\/p>\n<p>But maybe we want to do something a little different &#8211; like compare the change in population over time. Well, we can do that easily by visualizing each row of <code>census-time-series.csv<\/code> rather than each column.`<\/p>\n<h2>Visualizing Data in Rows<\/h2>\n<pre>my_chart = Chart.from_csv('census-time-series.csv',\r\n                          series_type = 'line',\r\n                          series_in_rows = True,\r\n                          wrapper_character = '\"')<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2023\/10\/17203041\/Line-chart-using-data-from-the-table-above-US-gerographic-population.jpg\" alt=\"Line chart using data from the table above US gerographic population\" width=\"1160\" height=\"346\" class=\"alignnone size-full wp-image-24312\" srcset=\"https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2023\/10\/17203041\/Line-chart-using-data-from-the-table-above-US-gerographic-population.jpg 1160w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2023\/10\/17203041\/Line-chart-using-data-from-the-table-above-US-gerographic-population-560x167.jpg 560w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2023\/10\/17203041\/Line-chart-using-data-from-the-table-above-US-gerographic-population-760x227.jpg 760w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2023\/10\/17203041\/Line-chart-using-data-from-the-table-above-US-gerographic-population-768x229.jpg 768w\" sizes=\"auto, (max-width: 1160px) 100vw, 1160px\" \/><\/p>\n<p>Okay, so here we removed some of the other arguments we\u2019d been using to simplify the example. You\u2019ll see we\u2019ve now added the <code>series_in_rows<\/code> argument, and set it to <code>True<\/code>. This tells <b>Highcharts for Python<\/b> that we expect to produce one series for every row in <code>census-time-series.csv<\/code>.<\/p>\n<p>Because we have not specified a <code>property_column_map<\/code>, the series <code>.name<\/code> values are populated from the <code>'Geographic Area'<\/code> column, while the data point <code>.x<\/code> values come from each additional column (e.g. &#8216;2010&#8217;, &#8216;2011&#8217;, &#8216;2012&#8217;, etc.)<br \/>\n<i><b>Tip<\/b><\/p>\n<p>To simplify the code further, any class that supports the <code>.from_csv()<\/code> method also supports the <code>.from_csv_in_rows()<\/code> method. The latter method is equivalent to passing <code>series_in_rows = True<\/code> to <code>.from_csv()<\/code>.<\/p>\n<p>For more information, please see:<\/p>\n<ul>\n<li><code>Chart.from_csv_in_rows()<\/code><\/li>\n<li><code>SeriesBase.from_csv_in_rows()<\/code><\/li>\n<\/ul>\n<p><\/i><\/p>\n<p>But maybe we don\u2019t want all geographic areas shown on the chart &#8211; maybe we only want to compare a few.<\/p>\n<h2>Filtering Rows<\/h2>\n<pre>my_chart = Chart.from_csv('census-time-series.csv',\r\n                          series_type = 'line',\r\n                          series_in_rows = True,\r\n                          wrapper_character = '\"',\r\n                          series_index = slice(7, 10))<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2023\/10\/17203516\/Line-chart-using-data-from-the-table-above-US-gerographic-population-for-3-states.jpg\" alt=\"Line chart using data from the table above US gerographic population for 3 states\" width=\"1160\" height=\"338\" class=\"alignnone size-full wp-image-24313\" srcset=\"https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2023\/10\/17203516\/Line-chart-using-data-from-the-table-above-US-gerographic-population-for-3-states.jpg 1160w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2023\/10\/17203516\/Line-chart-using-data-from-the-table-above-US-gerographic-population-for-3-states-560x163.jpg 560w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2023\/10\/17203516\/Line-chart-using-data-from-the-table-above-US-gerographic-population-for-3-states-760x221.jpg 760w, https:\/\/wp-assets.highcharts.com\/www-highcharts-com\/blog\/wp-content\/uploads\/2023\/10\/17203516\/Line-chart-using-data-from-the-table-above-US-gerographic-population-for-3-states-768x224.jpg 768w\" sizes=\"auto, (max-width: 1160px) 100vw, 1160px\" \/><\/p>\n<p>What we did here is we added a <code>series_index<\/code> argument, which tells <b>Highcharts for Python<\/b> to only include the series found at that index in the resulting chart. In this case, we supplied a <code>slice<\/code> object, which operates just like <code>list_of_series[7:10]<\/code>. The result only returns those series between index 7 and 10.<\/p>\n<h2>Creating Series: .from_csv() and .from_csv_in_rows()<\/h2>\n<p>All <b>Highcharts for Python<\/b> <code>series<\/code> descend from the <code>SeriesBase<\/code> class. And they all therefore support the <code>.from_csv()<\/code> class method.<\/p>\n<p>When called on a series class, it produces one or more series from the CSV supplied. The method supports all of the same options as <code>Chart.from_csv()<\/code> except for <code>options_kwargs<\/code> and <code>chart_kwargs<\/code>. This is because the <code>.from_csv()<\/code> method on a series class is only responsible for creating series instances &#8211; not the chart itself.<\/p>\n<h2>Creating Series from Columns<\/h2>\n<p>So let\u2019s say we wanted to create one series for each of the years in <code>census-time-series.csv<\/code>. We could do that like so:<\/p>\n<pre>my_series = BarSeries.from_csv('census-time-series.csv')<\/pre>\n<p>Unlike when calling <code>Chart.from_csv()<\/code>, we did not have to specify a <code>series_type<\/code> &#8211; that\u2019s because the <code>.from_csv()<\/code> class method on a series class already knows the series type.<\/p>\n<p>In this case, <code>my_series<\/code> now contains ten separate <code>BarSeries<\/code> instances, each corresponding to one of the year columns in <code>census-time-series.csv<\/code>.<\/p>\n<p>But maybe we wanted to create our series from rows instead?<\/p>\n<h2>Creating Series from Rows<\/h2>\n<pre>my_series = LineSeries.from_csv_in_rows('census-time-series.csv')<\/pre>\n<p>This will produce one <code>LineSeries<\/code> instance for each row in <code>census-time-series.csv<\/code>, ultimately producing a list of 57 <code>LineSeries<\/code> instances.<\/p>\n<p>Now what if we don\u2019t need all 57, but instead only want the first five?<\/p>\n<h2>Filtering Series Created from Rows<\/h2>\n<pre>my_series = LineSeries.from_csv_in_rows('census-time-series.csv', series_index = slice(0, 5))<\/pre>\n<p><b>This will return the first five series in the list of 57.<\/b><\/p>\n<h2>Updating an Existing Series: .load_from_csv()<\/h2>\n<p>So far, we\u2019ve only been creating new series and charts. But what if we want to update the data within an existing series? That\u2019s easy to do using the <code>.load_from_csv()<\/code> method.<\/p>\n<p>Let\u2019s say we take the first series returned in <code>my_series<\/code> up above, and we want to replace its data with the data from the 10th series. We can do that by:<\/p>\n<pre>my_series[0].load_from_csv('census-time-series.csv',\r\n                           series_in_rows = True,\r\n                           series_index = 9)<\/pre>\n<p>The <code>series_in_rows<\/code> argument tells the method to generate series per row, and then the <code>series_index<\/code> argument tells it to only use the 10th series generated.<\/p>\n<p><i><b>Caution<\/b><\/p>\n<p>While the <code>.load_from_csv()<\/code> method supports the same arguments as <code>.from_csv()<\/code>, it expects that the arguments supplied lead to an unambiguous single series. If they are ambiguous &#8211; meaning they lead to multiple series generated from the CSV &#8211; then the method will throw a <code>HighchartsCSVDeserializationError<\/code><br \/>\n<\/i><\/p>\n<p>\u00a0<\/p>\n<h2><strong>Related posts<\/strong><\/h2>\n<ul>\n<li style=\"margin-left: 20px; margin-bottom: 20px;\"><a href=\"https:\/\/www.highcharts.com\/blog\/tutorials\/line-chart-vs-bar-chart-choosing-the-right-one-for-your-objectives-and-data\/\">Line chart vs bar chart: choosing the right one for your objectives and data<\/a><\/li>\n<li style=\"margin-left: 20px; margin-bottom: 20px;\"><a href=\"https:\/\/www.highcharts.com\/blog\/tutorials\/pareto-chart-what-is-it-and-what-does-it-suggest\/\">Pareto chart: what is it and what does it suggest<\/a><\/li>\n<li style=\"margin-left: 20px; margin-bottom: 20px;\"><a href=\"https:\/\/www.highcharts.com\/blog\/post\/polygon-chart-using-highcharts\/\">Polygon chart using Highcharts<\/a><\/li>\n<li style=\"margin-left: 20px; margin-bottom: 20px;\"><a href=\"https:\/\/www.highcharts.com\/blog\/post\/choropleth-map-examples-using-highcharts\/\">Choropleth map examples using Highcharts<\/a><\/li>\n<li style=\"margin-left: 20px; margin-bottom: 20px;\"><a href=\"https:\/\/www.highcharts.com\/blog\/tutorials\/lightning-map-create-your-own-using-highcharts\/\">Lightning map: create your own using Highcharts<\/a><\/li>\n<li style=\"margin-left: 20px; margin-bottom: 20px;\"><a href=\"https:\/\/www.highcharts.com\/blog\/tutorials\/maps-with-latitude-longitude-using-highcharts\/\">Maps with latitude longitude using Highcharts<\/a><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>CSV (Comma-Separated Value) is one of the most common formats for exchanging data files &#8211; both large and small. Because of its popularity, the Highcharts for Python Toolkit is designed to work seamlessly with it. General Approach The Highcharts for Python Toolkit provides a number of standard methods that are used to interact with CSV [&hellip;]<\/p>\n","protected":false},"author":273,"featured_media":24337,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"meta_title":"","meta_description":"","hc_selected_options":[],"footnotes":""},"categories":[1105],"tags":[1094,885],"coauthors":[983,699],"class_list":["post-24320","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-integration","tag-highcharts-core","tag-python"],"_links":{"self":[{"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/posts\/24320","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/users\/273"}],"replies":[{"embeddable":true,"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/comments?post=24320"}],"version-history":[{"count":3,"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/posts\/24320\/revisions"}],"predecessor-version":[{"id":26050,"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/posts\/24320\/revisions\/26050"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/media\/24337"}],"wp:attachment":[{"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/media?parent=24320"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/categories?post=24320"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/tags?post=24320"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.highcharts.com\/blog\/wp-json\/wp\/v2\/coauthors?post=24320"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}