无法在python中创建注释脚本

时间:2019-03-11 09:57:18

标签: python excel list csv

我试图用python创建注释工具来编辑大型csv文件并生成json输出,但是作为一名较新的程序员,我遇到了很多困难。

我生成了两个csv文件,然后从一个文件中获得了要匹配的行和列的列表: filtered list of columns and rows

另一个文件有一个输出列表,我希望将其与之匹配并收集指定的数据条目:raw outputs

例如,我想将Q5.3列的第6行中的数据与原始问题一起打印,然后指定其好坏。如果不好,我希望能够添加评论。

我想生成一个最终将其编译的json文件。我试图编写代码,但这是完全的垃圾,我想我希望能够了解如何正确实现,并且变得非常困惑。

任何帮助将不胜感激!

输出应通过所有指定的数据并打印: 问题编号 题, 响应, 注释为好或坏, 如果不好,则可以添加评论, 继续下一个数据, 完成后,为数据生成json

谢谢:)

我的尝试:

import csv
from csv import reader
import json

csv_results_path = 'results.csv'
categories = { '1':'Unacceptable', '2':'Edit'}

# Checking the outputs (comment out) 
''''
print(rows)
print(columns)
'''

'''
# Acquire data from specifed row, column in responses
# Example row 6, column '12.2'
'''



def get_annotation_input():
    while True:
        try:
            annotation = int(input("Annotation: "))
            if annotation not in range (1,3):
                raise ValueError
            return annotation, edited_comment
        except ValueError:
            print("Enter 1 or 2") 


def annotate():
          annotator = input("What is your name? ")
          print(''.join(["-"]*50))
          print("Annotate the following answer as 1-Unacceptable, 2-Edit")


          with open("annotations.json", mode='a') as annotation_file:
              annotation_data = ('annotator': annotator, 'row_number':, 'question_number': , 'annotation' : categories[str(annotation)], 'edited_response': }
              json.dump(annotation_data, annotation_file)
              annotation_file.write('\n')


if __name__ == "__main__":
    annotate()

with open('annotations_full.csv', 'rU') as infile:
              response_reader = csv.DictReader(infile)
              responses = {}
              for row in response_reader:
                  for header, response in row.items():
                      try:
                          responses[header].append(response)
                      except KeyError:
                          responses[header] = [response]
rows = responses['row_number']
columns = responses['question_number']
print(rows)
print(columns)

我成功地获得了想要的行和列的列表,但是,我很难使用行和相应的列来显示和注释来访问另一个csv文件中的数据。同样,当我尝试编写代码以允许一个字段(如果指定了“ 2”)用于编辑响应时,我会遇到很多输出错误。

0 个答案:

没有答案