Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Excel - Python
#2
Not a mathematician, don't know about standard deviation or pandas.

This will get your data as a list of tuples. You can work on it then.

import openpyxl
import re

# open the XL
path2XL = '/home/pedro/myPython/openpyxl/xlsx_files/get_data1.xlsx'
sourceFile = openpyxl.load_workbook(path2XL)
# always good to get the sheet names, you can loop through them if you need to
sourceFilesheets = sourceFile.sheetnames
mysheet = 'Standard'
# you often need these 2 to loop along or down an XL
maxRow = sourceFile[mysheet].max_row
maxCol = sourceFile[mysheet].max_column
# if your column is H, that is column 8
# openpyxl does have a "get column number from letter" function, but H is column 8
# I assume your data starts in row 2 change that if needed
# loop through all the rows and collect your data

results = []
for rowNum in range(2, maxRow + 1):
    mystring = sourceFile[mysheet].cell(row=rowNum, column=8).value
    # split the string on space, the number you want is at the end, separated by a space I think!
    mydata = mystring.split()
    # re.search only returns 1 instance, I believe
    mystd = re.search(r'std\d\d', mydata[0])
    mynumber = int(mydata[1])
    mytup = ('Row ' + str(rowNum), mystd[0], mynumber)
    results.append(mytup)

for data in results:
    print(data)

print('Gotcha!')
Reply


Messages In This Thread
Excel - Python - by bckdw3tci6 - Jun-24-2023, 04:19 PM
RE: Excel - Python - by Pedroski55 - Jun-24-2023, 10:55 PM
RE: Excel - Python - by bckdw3tci6 - Jun-25-2023, 01:42 PM
RE: Excel - Python - by Pedroski55 - Jun-25-2023, 09:15 PM
RE: Excel - Python - by Pedroski55 - Jun-25-2023, 09:25 PM

Forum Jump:

User Panel Messages

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