Answer the question
In order to leave comments, you need to log in
How to use data from excel spreadsheets in python script?
Hello, there are a number of Excel tables in which numeric data is in two columns
. Is it possible to use this data in some way? You need to refer to them somehow, use them in a script
Answer the question
In order to leave comments, you need to log in
Alexander has already advised openpyxl. I will answer in a slightly different way.
To get started, it would be nice to see an example of the file you want to parse.
No need to import to CSV. Openpyxl can do everything by itself.
from openpyxl import load_workbook
wb = load_workbook("/path/to/file.xls") # Открываем файл
sheet = wb.get_sheet_by_name('New Sheet') # Выбираем лист
# Выбираем диапазон заполненных ячеек
max_row = sheet.max_row # Последняя заполненная строка
max_col = sheet.max_column # Последняя заполненная колонка
for r in range(1, max_row + 1):
for c in range(1, max_column + 1):
val = sheet.cell(row=r, column=c).value # Получаем в цикле значение в конкретной ячейке
# do something
Save the Excel file in CSV format, and it is convenient to process it in the pandas dataframe
#устанавливаем pandas
!pip install pandas
#импортируем библиотеку pandas
import pandas as pd
# Читаем из 'excel.csv'
data = pd.read_csv("excel.csv")
# Выводим первые строчки
data.head()
Save to CSV - the original solution, I use this one:
https://openpyxl.readthedocs.io/en/stable/
Reads, writes
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question