Pandas xlsxwriter folded string

I want to load the grouped barchart into excel, however I cannot find a way to do it.

Here is my code:

bar_chart2 = workbook.add_chart({'type':'column'})
bar_chart2.add_series({
    'name':'Month over month product',
    'categories':'=Month over month!$H$2:$H$6',
    'values':'=Month over month!$I$2:$J$6',
    })
bar_chart2.set_legend({'none': True})

worksheet5.insert_chart('F8',bar_chart2)

bar_chart2.set_legend({'none': True})

worksheet5.insert_chart('F8',bar_chart2)

      

However, I understand. enter image description here

+3


source to share


1 answer


Using the data provided, I have reprocessed the example provided in the jmcnamara Docs (link here ) to match what you are looking for.

Complete code:



import pandas as pd
import xlsxwriter

headings = [' ', 'Apr 2017', 'May 2017']
data = [
    ['NGN', 'UGX', 'KES', 'TZS', 'CNY'],
    [5816, 1121, 115, 146, 1],
    [7089, 1095, 226, 120, 0],
]

#opening workbook
workbook = xlsxwriter.Workbook("test.xlsx")

worksheet5 = workbook.add_worksheet('Month over month')

worksheet5.write_row('H1', headings)
worksheet5.write_column('H2', data[0])
worksheet5.write_column('I2', data[1])
worksheet5.write_column('J2', data[2])

# beginning of OP snippet
bar_chart2 = workbook.add_chart({'type':'column'})

bar_chart2.add_series({
    'name':       "='Month over month'!$I$1",
    'categories': "='Month over month'!$H$2:$H$6",
    'values':     "='Month over month'!$I$2:$I$6",
 })

bar_chart2.add_series({
    'name':       "='Month over month'!$J$1",
    'categories': "='Month over month'!$H$2:$H$6",
    'values':     "='Month over month'!$J$2:$J$6",
})

bar_chart2.set_title ({'name': 'Month over month product'})
bar_chart2.set_style(11)

#I took the liberty of leaving the legend in there - it was commented in originally
#bar_chart2.set_legend({'none': True})

# end of OP snippet

worksheet5.insert_chart('F8', bar_chart2)

workbook.close()

      

Output: enter image description here

+2


source







All Articles