使用图表Python创建多个xlsx文件

时间:2018-01-25 01:51:11

标签: python csv charts xlsx

我正在寻找一个巨大的python代码来从我的csv数据创建xlsx文件。我需要Cliente的文件,在那里我需要有关Cliente的所有信息,因为我向您展示。关键是我需要在Cliente中分隔csv数据并为每个Cliente运行我的代码

                    Cliente       Fecha      Subastas  Importe_a_pagar_a_medio
0                    ID         01/12/2017    1000                     1.78
1                    ID         02/12/2017    1200                     1.20

在另一个档案中:

                    Cliente       Fecha      Subastas  Importe_a_pagar_a_medio
2                    Ad         01/12/2017     600                     4.46
3                    Ad         02/12/2017     800                     4.66
4                    Ad         03/12/2017    1000                     4.86

我有一个简单的xlsx代码来绘制我的图表:

import pandas as pd


df = pd.read_csv('ac.csv')
subastadas = list(df['Subastadas'])
revenue = list(df['Revenue'])
fecha = list(df['Fecha'])

import xlsxwriter

workbook = xlsxwriter.Workbook('chart_line.xlsx')
worksheet = workbook.add_worksheet()

# Add the worksheet data to be plotted.
data = subastadas

worksheet.write_column('A1', fecha)
worksheet.write_column('B1', data)
worksheet.write_column('C1', revenue)
# Create a new chart object.
chart = workbook.add_chart({'type': 'line'})
chart2 = workbook.add_chart({'type': 'line'})
# Add a series to the chart.
chart.add_series({'values': '=Sheet1!$B$1:$B$3', 'categories': '=Sheet1!$A$1:$A$3', 'line':{'color': 'red'}})
chart2.add_series({'values': '=Sheet1!$C$1:$C$3', 'categories': '=Sheet1!$A$1:$A$3', 'line':{'color': 'blue'}})
# Insert the chart into the worksheet.
worksheet.insert_chart('F1', chart)
worksheet.insert_chart('F15', chart2)
workbook.close()

csv数据:

                    Cliente       Fecha      Subastas  Importe_a_pagar_a_medio
0                    ID         01/12/2017    1000                     1.78
1                    ID         02/12/2017    1200                     1.20
2                    Ad         01/12/2017     600                     4.46
3                    Ad         02/12/2017     800                     4.66
4                    Ad         03/12/2017    1000                     4.86

0 个答案:

没有答案