I'm trying to create a tracker of stuff I do every day, like the amount of water I drink, how much I exercise, read, whatever, and store that info in two sheets, one with 365-day info and one with all the days
I also want to have an excel graph that I can quickly take a look at (meaning I don't want to have to set it up every time I want to see it). Doing that for the 365 days thing should be easy by just setting a locked range of 365 cells, but in any case it would only look pretty once I've been using it for some months.
This webpage shows exactly how to do it when you input the info manually, but I'm using openpyxl to input the info for me via a telegram bot. I tried doing that then adding a value right below the table with code and it doesn't work.
My theory is that once you call that cell it gets emptied of any kind of attributes (format) it might have before setting a value.
Example: If you make the cells (B2:D4) have all borders and then execute ws['C3'] = 5, it will remove the borders of that cell because you didn't explicitly told Excel to "keep them" (or, more accurate, set them again)
The example can be fixed using openpyxl.styles, but how do I make excel "check", or add new values to the existing table? I assume that if I get them to join the table, they will be added to the graph too.
This is a personal project, not an assignment or anything, so if there's another way to do the same, I'm okay with that.
Edit: I've been playing with dir(ws.tables['Table1']) and found an (attribute?) called insertRow, but I can't find anything at all that explains what it does, only how it works (Boolean that allows None). I tried manually changing it from None to True and then trying again, but when I opened the file it said it needed to be repaired, and when repaired it added the value but didn't make it join the table...
Related
I am performing data analysis. I want to segment the steps of data analysis into different projects, as the analysis will be performed in the same order, but not usually all at the same time. There is so much code and data cleaning that keeping all of this in the same project may get confusing.
However, I have been keeping any header files for tracking columns of information in the data consistent. It is possible I will change the sequence of these headers at some point and want to run all sequences of code. I also want to make sure that the header used remains the same so I don't erroneously analyze one piece of data instead of another. I use headers so that if a column order changes at any time, I am accessing the index of the data based on the header that matches the data changes rather than changing every instance of appearance of a particular column number throughout my code.
To accomplish this, I would like to file track multiple projects that access the SAME header files, and update and alter the header files without having to access the header files from each project individually.
Finally, I don't want to just store it somewhere on my computer and not track it, because I work from two different work stations.
Any good solutions or best practice for what I want to do? Have I made an error somewhere in project set-up? I am mostly self-taught and so have developed my own project organization and sequence of data analysis based on my own ideas and research as I go, so if I've done some terribly bad practice that would be great to know.
I've found a possible solution that uses independent branches in the same repo for tracking two separate projects, but I'm not convinced this is the best solution either.
Thanks!
I plan to make an educational web game. I have thousands of trivia questions I need to write down in a way that can be easily transferred out and automatically organized based on their column, at a later date.
I was suggested to use google sheets so I can later export as a .csv, and that should be easy to work with for a developer. When i exported a .csv and opened it in Panda python the a column was cut off and 1 column was used as a 'header', not just a normal entry https://imgur.com/a/olcpVO8. This obviously wont work and seems to be an issue.
Should I just leave the first row and column empty and work around the issue? I don't want to write thousands of sets only to find out I did this the wrong way. Can anyone give any insight into whether this is my best option and how I should best format it?
I have to write Questions(1), Answers(4), Explanations(1) per entry
I hope this makes sense, thanks for your time.
I tried doing this and have no issue at all using the exported CSV from Google Sheets, using the same data as in your example.
In my opinion, whatever software you're using in your second screenshot is your issue, it seems like its removing numbers from the first row because that should be your header row. Check around in your software for options like, "First column contains headers" or "Use row 1 as Header" and make sure these aren't being used.
For my python script, there is one missing simple trick when I want to take data from Excel with Python win32com.
I just want to know how to get selected cells information, e.g. col/row for my python script. For example I could specify the range as shown below, but I simply cannot do the same thing to the selected/active cells.
ws.Range("B1:AM167").CopyPicture()
Does someone help me with this?
I am quite new to win32, so I still do not know how to find correct method/property etc...
Try Application.Selection.
The returned object type depends on the current selection (for
example, if a cell is selected, this property returns a Range object).
The Selection property returns Nothing if nothing is selected.
I made a sheet with a graph using python and openpyxl. Later on in the code I add some extra cells that I would also like to see in the graph. Is there a way that I can change the range of cell that the graph is using, or maybe there is another library that lets me do this?
Example:
my graph initially uses columns A1:B10, then I want to update it to use A1:D10
Currently I am deleting the sheet, and recreating it, writing back the values and making the graph again, the problem is that this is a big process that takes days, and there will be a point that rewriting the sheet will take some time.
At the moment it is not possible to preserve charts in existing files. With rewrite in version 2.3 of openpyxl the groundwork has been laid that will make this possible. When it happens will depend on the resources available to do the work. Pull requests gladly accepted.
In the meantime you might be able find a workaround by writing macros to create the charts for you because macros are preserved. A bit clumsy but should work.
Make sure that you are using version 2.3 or higher when working on charts as the API has changed slightly.
I have a Python script which populates Excel files with data from various sources, using Excel's COM interface. Here's a snippet:
file=win32com.client.Dispatch("Excel.Application")
#various manipulation goes here
file.DisplayAlerts=False
sheet.Delete()
file.DisplayAlerts=True
I need to delete one of the sheets after everything is populated, so I turn DisplayAlerts off so it doesn't ask me to confirm the deletion. I want to turn it on again afterwards, so users don't lose data. However, after DisplayAlerts is back on, switching sheets gives me this message: "A formula in this worksheet contains one or more invalid references. Verify that your formulas contain a valid path, workbook, range name, and cell reference". I don't normally get this message, and all of my formulas are working as expected. How can I avoid the message?
I'm pretty sure that the message has to do with the fact that I have charts which have a lot of #N/A values in their data ranges (so points don't get drawn). But what can I do to get rid of these messages, and why do they show up after those three lines of code? Also, just switching DisplayAlerts off and on again doesn't bring up the message: the deletion plays a role in this.
Also, is there some good reason for why that message doesn't just tell you where it sees a problem?
The message comes up only the first time a sheet is switched to, and returns every time an edit is made to the chart's range. Also, it doesn't come up if I just delete the sheet without turning off DisplayAlerts.