#๐Ÿ”’ Data analysis

7 messages ยท Page 1 of 1 (latest)

ionic agateBOT
#

@wispy charm

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

wispy charm
#

import openpyxl
from openpyxl.styles import PatternFill

file_path = 'C:\Users\A\Documents\Math assignment\data1.xlsx'
workbook = openpyxl.load_workbook(file_path)
this my code
sheet1 = workbook['Sheet1']
random_numbers_sheet1 = {cell.value: cell.row for cell in sheet1['A'][1:17]}

sheets_to_process = ['Sheet2', 'Sheet3', 'Sheet4']

for sheet_name in sheets_to_process:
sheet = workbook[sheet_name]

for col_idx in range(1, sheet.max_column + 1):
    col_letter = openpyxl.utils.get_column_letter(col_idx)
    
    column_data = [cell.value for cell in sheet[col_letter]]

    last_filled_row = None
    for row_idx, number in enumerate(column_data, start=1):
        if number is not None and number != '' and number in random_numbers_sheet1:
            fill = PatternFill(start_color="FFFF00", end_color="FFFF00", fill_type="solid")
            sheet[f"{col_letter}{row_idx}"].fill = fill
            last_filled_row = row_idx

    sheet[f"{col_letter}41"] = last_filled_row if last_filled_row is not None else ''

workbook.save(file_path)

#

I want to use Python code to read an Excel file, find the row number of the last cell with filled color in each column, and record this row number in the 41st row of each column. This operation is only needed for sheets 2 to 4 in my Excel file named "data1". I already have openpyxl installed in my Python environment.

#

but when i run this command the data, it fill from 2-40 , they are not the same data given in sheet 1

#

I really can't find where the problem

ionic agateBOT
#

@wispy charm

Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.