На второй итерации через вложенный цикл я получаю ошибку:
"Файл
"C: \ Users \ SmithC113 \ PycharmProjects \ ASCII_Word \ venv \ Lib \ сайт-пакеты \ панды \ ю \ форматы \ format.py",
строка 1404, в
return (len (non_na)> 0 и все (x.endswith ('0') для x в non_na) и SystemError: ошибка возврата без установленного исключения. "
Я не могу понять, что является причиной этой ошибки. Любая помощь приветствуется.
Я попробовал dict.clear, думая, что словарь просто автоматически добавляет данные из массива, но это не сработало. Я также попробовал dict.update в сочетании с и без dict.clear. Я не понимаю ошибку, поэтому трудно найти решение.
import tkinter as tk
from tkinter.filedialog import askopenfilename
import pandas as pd # Pandas - gives better table display results
from docx import Document # Invokes Document command from docx
from docx.shared import Pt # This makes it possible to dictate the font size we are writing to the doc-x
# IMPORT ASCII CP DATA
root = tk.Tk()
root.withdraw()
file_path = askopenfilename(title="Choose Control File") # returns the file path as variable for future use
data = pd.read_csv(file_path, sep=",", header=None)
r = len(data[1]) # number of rows in ASCII file (aka number of 3D points)
print('Number of CP Points imported =', r) # This is check for now
# IMPORT ASCII BM DATA
file_pathBM = askopenfilename(title='Choose Benchmark File') # returns the file path as variable for future use
data_bm = pd.read_csv(file_pathBM, sep=",", header=None)
rbm = len(data_bm[1]) # number of rows in ASCII file (aka number of 3D points)
print('Number of BM Points imported =', rbm) # This is check for now
# IMPORT WORD DOCUMENT
root = tk.Tk()
root.withdraw()
doc_path = askopenfilename(title="Choose Word File") # returns the file path as variable for future use
document = Document(doc_path) # Imports Word Document to Modify
t = len(document.paragraphs) # gives the number of lines in document
print('Total Number of lines =', t) # this is a check for now
font = document.styles['Normal'].font
font.name = 'Arial'
font.size = Pt(8)
x = 0
for paragraph in document.paragraphs:
data_dict = {
'NORTHING:': data[1][x],
'EASTING:': data[2][x],
'ELEV:': data[3][x],
'CSF:': data[8][x],
'STD. DEV.:': 'N: {0}\t E: {1}\t EL: {2}'.format(data[5][x], data[6][x], data[7][x])
}
for k, v in data_dict.items():
if k in paragraph.text:
paragraph.clear()
run = paragraph.add_run()
run.text = k + '\t'
run.font.bold = True
run.font.underline = True
run = paragraph.add_run()
run.text = '{}'.format(v)
x += 1
data_dict.clear()
for paragraph in document.paragraphs:
print(paragraph.text) # Prints the text in the entire document
# document.save('test1_save.docx') #Saves as Word Document after Modification
В отладчике я вижу, что значения словаря перезаписываются так, как я хочу, но во время второй итерации в операторе if я получаю вышеуказанную ошибку. Я сбит с толку, потому что данные имеют тот же тип, что и первая итерация, а словарь представляет собой одно значение data [y] [x]. Также вам понадобятся панды, python-docx и numpy.
Фрагмент данных из файла ASCII:
1,126081.2245,12608965.8380,691.5940, CP, 0.0053,0.0036,0.0006,1.0000470038
2,126327.6401,12609040.7808,692.2263, CP, 0.0041,0.0043,0.0009,1.0000467574
3,126738.8659,12609037.5712,691.4403, CP, 0.0043,0.0058,0.0030,1.0000464372
4,127066.6430,12608990.3587,690.2438, CP, 0.0051,0.0050,0.0011,1.0000462105
5,127303.7734,12609061.0079,692.1387, CP, 0.0030,0.0053,0.0029,1.0000459125
вставьте его в текстовый файл и используйте для обоих импортов
Формат документа Word следующий:
CP1
ОПИСАНИЕ: УСТАНОВИТЕ ЖЕЛЕЗНОДОРОЖНЫЙ БАР 5/8 ”X 36” С ЗАГОТОВКОЙ MOTOT В СЕВЕРНО
Квадрант главной улицы и М-51.
СВИДЕТЕЛИ:
ПОЖАРНЫЙ ГИДРАНТ S42W 30,5 ’
СВЕТОВОЙ ПОЛЮС N08E 27,0 ’
СВЕТОВОЙ ПОЛЮС N47E 70,0 ’
ЦЕНТР СБОРНОЙ УБОРКИ S45W 24,0 ’
СЕВЕР:
ВОСТОЧНЫЙ:
ELEV:
CSF:
STD. DEV .: N: E: ELEV:
STATION:
СМЕЩЕНИЕ:
CP2
ОПИСАНИЕ: КОМПЛЕКТ 5/8 ”X 36” ЖЕЛЕЗНОДОРОЖНЫЙ БАР С MDOT CAP НА ЮГО-ВОСТОКЕ
Квадрант улицы Сикамор и М-51.
СВИДЕТЕЛИ:
ШТОРНЫЙ ЛЮК S73W 10,0 ’
БАССЕЙН С ЗАМКАМИ 45,0 ’
ТРУБОПРОВОД S53W 20,5 ’
УГЛОВОЙ УГОЛОК S43W 11,5 ’
СЕВЕР:
EASTING:
ELEV:
CSF:
STD. DEV .: N: E: ELEV:
STATION:
OFFSET: