I have a program which takes DataFrame and writes it into excel as chart(using xlsxwriter and pandas libraries). For example, I wrote column-stacked-chart into excel.
What I want now is to add line chart to that excel chart which was created before. This isn't problem if I write them in the same function, but first chart is already created and I don't have that object in another code. I want to combine them, so I need to get list of charts in excel to take first one, create second and combine them.
Related
I have been trying to generate a code in python that automatically creates a graph from unknown amount of data point in an excel spread sheet.
The data in the excel sheet does not always have the same ending point so I need the code to automatically read how many data points are in the excel file and graph it automatically. It also has to be able to handle large numbers of data point like into the 4000's. And also find the average, max and min.
Sample of the excel data (I only need it to read the first two columns which will be the x and y)
I have a main dataframe called df1, from this df1 I take six different dataframes based on different conditions. Later I write all this to different excel sheets, So my excel sheet will have 6 sheets.
What I want to do is that I need to colour the column heading of A:D with one colour, E:H to another colour etc. But xlsx writer is already taking time without formatting the file so with formatting it could take much more time.
So I wonder if somehow I can set colour to df1 itself and when taking data from it, all the six df will already have the format property.
What is the best way to do this ?
I have an Excel file with multiple sheets. With the data I retrieve from another Excel file, I want to add matplotlib charts to each sheet. However, although the plots are generated and shown in the console while the loop runs, once the loop is finished, all the sheets have the last chart added; the one that's supposed to be added to the last sheet.
I tried breaking down the loop and going manually, e.g., plot scheme for sheet[0], for sheet[1], etc. This gave the same result. I don't know if I'm doing something wrong or this is some sort of bug in openpyxl.
sheets = wb.sheetnames
for i in range(0, len(sheets)):
#Iterate over sheets
ws = wb[sheets[i]]
#The chart code
. . .
#I save the current plot to be added to the Excel sheet using openpyxl
fig1.savefig("myplot.png", dpi = 72)
#Add the saved chart to the active excel sheet, which is the current iteration in the loop
img = openpyxl.drawing.image.Image('myplot.png')
ws.add_image(img)
wb.save('Excel_file.xlsx')
At each iteration a new chart is supposed to be added to the active sheet. But I get the last chart in all of them at the end.
The Excel file with the charts added is supposed to be the final form of a fully automated report. I am not using openpyxl's charts instead of matplotlib because I need the flexibility and customizability of the latter.
Any help is appreciated. Many thanks.
I am working with .csv dataset that I download from an online source. There are two date columns in the file that come in a custom excel format of "d-mmm", but when you highlight over a cell it shows the contents of the cell in "mm/dd/yyyy" format (this is in the formula box, not the cell itself).
Picture to illustrate my problem: https://imgur.com/0qm9ScH
I'm struggling with getting the correct date format in python without manually changing the data type in excel.
Like stated, I have tried to manually change the data types and this works...but then I would have to do this in 15 different .csvs and whenever I update the .csvs, I would have to repeat the process.
I have also tried using parse_dates and date_parser in my pandas read_csv, but haven't had any luck
Ideally, there would be some process that would open up a .csv, read the contents of the two date fields, and convert from "d-mmm" (as shown) to "mm/dd/yyyy" as desired.
Is this possible or would I have to manually change data types within excel?
How does one manipulate the format of the excel sheet using python?
My code currently is taking data from several spreadsheets and is pulling the data I want from these sheets into a single workbook. I want the formatting of the workbook to be consistent, because every iteration of the code just saves over the previously made one.
example I want the Cell A1 to be extended and background of the cell to be blue, but I need A2 background to be red