Python Forum
{SOLVED]Help getting formula value in Excel to a csv
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
{SOLVED]Help getting formula value in Excel to a csv
#1
I have an Excel file allscoresCLASS.xlsx, where CLASS might be 20BE or similar.

Column 1 is id, column 2 is name, column 3 in studentnr.

Then I have columns 4 to 19 as Week1 .... Week19

The last column is your_score, it is the sum of the scores in the columns Week1 to Week19 (e.g. =SUM(D2:V2)).

I read the student numbers and scores each week from my webpage with pymsql and put them in the timetable.

Now I need this Excel file as a CSV file, to import it back into the MySQL table allstudentsScoresCLASS, so the students can click a button on the webpage and see their scores.

I don't want to keep opening the Excel by hand and then "save as .csv" when Python can do that.

Pandas seemed a quick way to do this:

# the target file is already saved with the newest scores
# I need it as a .csv to import into MySQL on the webpage

import pandas as pd

target = f'allscores{clas}.xlsx'
pathTarget = '/var/www/mycsvfiles/'

print('Now converting to csv .... ')
newname = target.split('.')
savename = newname[0] + '.csv'
read_file = pd.read_excel (pathTarget + target)
read_file.to_csv (pathTarget + savename, index = None, header=True)
This works great, but I don't get the value in the last column, your_score. That column in the csv is empty when pandas makes the csv.

I can't think of a trick to make pandas get the numerical value of the formula in column your_score.

Any tips please??
Reply
#2
Ah well, wasn't so tricky, just read the Excel a dataframe, then:

df.to_csv(pathTarget + savename)
Never use pandas really, so no experience.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Help using a dynamic array excel formula with XLWings FXMonkey 2 1,289 Jun-06-2023, 09:46 PM
Last Post: FXMonkey
  math formula does not give the same result as bash script [SOLVED] AlphaInc 3 969 Apr-02-2023, 07:21 PM
Last Post: AlphaInc
  Openpyxl manipulate excel write formula SamLiu 0 1,052 Nov-04-2022, 03:00 PM
Last Post: SamLiu
  Python “Formula” Package: How do I parse Excel formula with a range of cells? JaneTan 1 2,677 Jul-12-2021, 11:09 AM
Last Post: jefsummers
  How do I read in a Formula in Excel and convert it to do the computation in Python? JaneTan 2 2,638 Jul-07-2021, 02:06 PM
Last Post: Marbelous
  Reading from Excel: value not formula! faryad13 0 2,349 Oct-28-2020, 09:52 PM
Last Post: faryad13
  Openpyxl: Excel formula & condition formatting removed JaneTan 0 3,637 Sep-25-2020, 07:02 AM
Last Post: JaneTan
  Want to add formula to excel sheet nagu4651 1 2,492 Dec-26-2019, 10:13 PM
Last Post: keuninkske

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020