Bisher habe ich es geschafft, bestimmte Teile der .txt
Datei in Python auszudrucken, aber ich kann nicht herausfinden, wie Sie den Betrag von meiner Gesamtmenge und abziehen Addieren Sie dann den ausstehenden Wert aus jeder Spalte.Wie kann ich zwei Werte subtrahieren, die ich von einer TXT-Datei habe
import csv
FILE_NAME = "paintingJobs.txt" #I use this so that the file can be used easier
COL_HEADERS = ['Number', 'Date', 'ID', 'Total', 'Status', 'Paid']
NUM_COLS = len(COL_HEADERS)#This will insure that the header of each column fits into the length of the data
# read file once to determine maximum width of data in columns
with open(FILE_NAME) as f:
reader = csv.reader(f, delimiter=',')
# determine the maximum width of the data in each column
max_col_widths = [len(col_header) for col_header in COL_HEADERS]
for columns in reader:
for i, col in enumerate(columns):
if "A" in columns and int(columns[5]) < int(columns[3]):
max_col_widths[i] = max(max_col_widths[i], len(repr(col)))
# add 1 to each for commas
max_col_widths = [col_width+1 for col_width in max_col_widths]
# read file second time to display its contents with the headers
with open(FILE_NAME) as f:
reader = csv.reader(f, delimiter=',')
# display justified column headers
print(' ' + ' '.join(col_header.ljust(max_col_widths[i])
for i, col_header in enumerate(COL_HEADERS)))
# display justified column data
for columns in reader:
if "A" in columns and int(columns[5]) < int(columns[3]):
print(columns)`
Dies ist das Ergebnis bisher:
Number Date ID Total Status Paid
['E5345', '22/09/2015', 'C106', '815', 'A', '400']
['E5348', '23/09/2015', 'C109', '370', 'A', '200']
['E5349', '25/09/2015', 'C110', '480', 'A', '250']
['E5353', '28/09/2015', 'C114', '272', 'A', '200']
['E5355', '29/09/2015', 'C116', '530', 'A', '450']
['E5363', '01/10/2015', 'C124', '930', 'A', '500']
['E5364', '02/10/2015', 'C125', '915', 'A', '800']
['E5367', '03/10/2015', 'C128', '427', 'A', '350']
['E5373', '10/10/2015', 'C134', '1023', 'A', '550']
Was ich tun möchte, ist eine neue Spalte hinzufügen, die die Differenz der Gesamt ist und die bezahlten
Hat die Frage - im Prinzip - etwas mit diesem Code-Blob zu tun, oder kann die Art des Problems von Ihrem eigentlichen Programm abgekoppelt werden? Wenn ja, tun Sie das bitte und stellen Sie ein [minimales Beispiel] (http://stackoverflow.com/help/mcve) bereit. – timgeb
Oder mit anderen Worten: Der Titel ist so eine einfache Frage, warum ist die Frage so kompliziert? – timgeb
Ok, bis jetzt habe ich es geschafft, csv zu bekommen, um es aus einer .txt-Datei anzuzeigen, jetzt möchte ich die 6. Spalte von der 4. Spalte –