append dataframe to excel with some part overwrite? - python

My goal now is to append dataframe into an existed excel with date as index. Since sometimes i need to use the program several times a day ,I want overwrite that day when doing so.
For example, if I have 02-02 to 02-19 data and I want to 02-20 data just not overwrite any thing but if i have 02-02 to 02-19 data and now i got whole day 02-19 data, i want it just overwrite where 02-19 data start.
I already successfully write the dataframe to the excel, how can i set the startrow to fullfill my need

use xlwings. You can find the cell no where your data ends in excel by using range.end('down'), which you can use as your start point for writing new dataframe .

Related

Python to create splices of data from multiple sheets, within condition-based row locations

I'm looking to make use of data contained within a terribly organized excel file.
Characteristics of the File:
308 separate sheets within the file
Each sheet is similarly formatted and structured but contain different data [values and volume]
Multiple tables are contained within each sheet and stacked as follows
Sheet structure
Spreadsheet is updated with some frequency -- sheets, tables and volumes might change -- so I want to avoid hardcoding any sheet_names or row numbers
It's not a ton of rows so I'm not overly concerned by performance. Most important is that the data is easy to use.
My goal is to extract each table across each worksheet and group them into a single table. somethign like this
ideal table form
I'm hoping there is a way to loop sheet by sheet, table by table. I've not figured out a way to do this, though, which out hard-coding the row values
example from actual sheet

How to split data with multiple filters into new file with python

Excel sheet with multiple filters (see picture)
In the above picture link, we see an excel file with each column presenting a filter. What I'm trying to find out is how can I create a new excel file that still possesses the same columns but with selected filters.
For example: if I want the new Excel sheet to only show data including "Ewallet" & "Credit card" (under the "Payment" column) and "Yangon" & "Mandalay" (under the "City" column), how would i go by doing this?
"City" column filter
"Payment" column filter
Therefore, the process should be pretty much picking and choosing what filters collectively from each column can be fitted into a single new excel sheet.
I am trying to do this with openpyxl, xlswings and/ or xlxswriter. I am also pretty new to python code but I do understand code when I read it.
Thank you

Automation of splitting excel sheets based on column values with Python

Consider I have a huge excel sheet, with multiple columns and entries. However, there exists a particular column (COLUMN A) containing boolean values 0s and 1s. Now I wish to split my parent excel sheet into 2 sheets, based on the values of the COLUMN A. I already know that this can be done using VBA codes. However, I wanna try this on python.
My idea is that we can iterate through the said column values, and if a condition is satisfied, pick up the whole row and write it in a new sheet.
I am learning the language, can use numpy and pandas a bit to create linear regression models and the like. I'd like to work on this 'personal-project'. Would be glad if anyone would help me with this, provide a few hints or something to start with. Thank you.
How I would go about it:
Read the full excel sheet into a pandas dataframe
df = pd.from_excel("file_name.xlsx")
Filter the dataframe by values in that columns
df1 = df[df["COLUMN A"]==1]
df0 = df[df["COLUMN A"]==0]
Read those new dataframes to a new excel workbook, or new excel sheet on an exisiting workbook, using the pandas ExcelWriter: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.ExcelWriter.html
Don't forget to handle missing data in column A, if there is any.
I am just a student, so perhaps there are more efficient ways to do this, but I use pandas quite a bit in my undergraduate research and this is what I would do. Best of luck you :)

Make hash on excel data to detect data changed with openpyxl

I have an excel file with a lot of sheets (100+). Each sheet is independant. I would like to know if the data in a specific sheet has been altered since it last was opened. At the moment, I have a solution based on a for loop on all the relevant cells and calculate a checksum from there. If it is different, then the sheet has been changed. The problem is that I need to access a lot of cells and python is notoriously slow at that kind of task.
My question is: would you people have a better solution than my very naive one that would be more efficient?
I am using pyopenxl, but I could use another library for this specific task but it must be a python library.
The data is not of a single kind: there is a mix of numbers and strings in each sheet. But every sheet is formatted with the same pattern. (i.e. always the same data type at a given coordinate)

Using pandas.DataFrame to get format of excel cell?

TLDR: Uploading an existing excel file to a pandas DataFrame using df = pd.read_excel(file.xlsx). Currently unable to find any way to get the format (in terms of the excel sheet, i.e. General, Number, Currency, etc.) from the DataFrame df. Does anyone have any suggestions?
Associated Topics: I know this is possible in PHP and C#, but I would prefer to stay in python for the simplicity.
You can set a style really easily in pandas, but I can't find any documentation which shows how to get a style for a particular item in the DataFrame.

Categories