Python Excel程序

2024-04-29 07:45:33 发布

您现在位置:Python中文网/ 问答频道 /正文

下面显示的程序从CSV文件读取数据并将其导入PSSEPSSE是一个潮流模拟程序。我的程序有效。在

我的下一个目标是从放入excel文件COLUMNS[G to L]的新列中读取新数据。我试图实现到这个函数中的数据psspy.two_winding_chng(from_busnum, to_busnum,VMAX,VMIN,'character value')列G到K的顺序与函数值类似。最后一个参数必须实现为字符串值。所以另一件事是在excel上读取一个变量并将其作为字符串传输。在

最后,我的目标是根据我现在的程序读取G到L列中的数据,其中包括“年”和“位置”,然后打印出B列到E列。有没有办法做到这一点?同样在L列中,该列表示第一年、第二年、第三年等的数据

有没有办法把L列和A列连接起来。我不能使用xlrd、熊猫模块或任何其他模块,这是学校计算机上安装的唯一模块。Excel工作表已过帐。A至L列描述如下: "year","busnum","busname","change","tla","location","from","to","max","min", 'character value', "year_linkup"。我的CSV表发布在这里。[Excel工作表][1]

import os, sys

PSSE_LOCATION = r "C:\Program Files (x86)\PTI\PSSE33\PSSBIN"
sys.path.append(PSSE_LOCATION)
os.environ['PATH'] = os.environ['PATH'] + ';' + PSSE_LOCATION
import psspy
import redirect
import csv

psspy.throwPsseExceptions = True

from Tkinter
import *
import tkFileDialog
import tkSimpleDialog
import tkMessageBox

root = Tk()
tkMessageBox.showinfo("Welcome", "Please select case: ")

root.fileName = tkFileDialog.askopenfilename(filetypes = (("PSSE CASES",
  "*.sav"), ("PSSE CASES", "*.raw*")))

STUDY_CASE = root.fileName

psspy.psseinit(10000)
psspy.case(STUDY_CASE)

LOAD_GEN_DATAFILE = 'C:\Users\RoszkowskiM\Documents\Working_Program\CSV.csv'

# read the entire CSV into Python.
data = list(csv.reader(open(LOAD_GEN_DATAFILE)))
mydict = {}
for row in data:
  year, busnum, busname, change, tla, location = row[0: 6]# convert the types from string to Python numbers

# If this is a year not seen before, add it to the dictionary
if year not in mydict:
  mydict[year] = {}

busses_in_year = mydict[year]
if location not in busses_in_year:
  busses_in_year[location] = []

# Add the bus to the list of busses that stop at this location
busses_in_year[location].append((busnum, busname, change))

year = raw_input("Please Select Year of Study: ")
print("\n")

commands = ["Millwood-Buchanan", "Astoria-East-Corona", "Bronx",
  "DUNWOODIE-North-Sherman_Creek",
  "Vernon", "Greenwood-
  StatenIsland ","
  West_49th ","
  East_13th ","
  Staten_Island ","
  East_River ",
  "East_View", "DUNWOODIE-SOUTH", "Corona-Jamaica", "Astoria-East-Corona-
  Jamaica ",
  "Astoria-West-Queensbridge-Vernon", "Astoria-West-Queensbridge"
]
max_columns = 50

for index, commands in enumerate(commands):
  stars_amount = max(max_columns - len(commands), 0)
row = "# {} {}({})".format(commands, "." * stars_amount, index + 1)
print(row)
location = raw_input(" \n The list above show the TLA Pockets as well as the ID numbers assigned to them ()\n\n Please enter the ID #: ")
print("\n")

# assume CSV has columns as described in the doc string

if year in mydict and location in mydict[year]:
  busses_in_year = mydict[year]
print("Here are all the busses at that location for that year and the new LOAD TOTAL: ")
print("\n")
for busnum, busname, change in busses_in_year[location]:
  change = float(change)
busnum = int(busnum)
print('Bus #: %d' % busnum, 'Area Station: %s' % busname, 'New_load: %d MW' % change)

psspy.bsys(1, 0, [0.0, 0.0], 0, [], 1, [busnum], 0, [], 0, [])
psspy.scal_2(1, 0, 1, [0, 0, 0, 0, 0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0])
psspy.scal_2(0, 1, 2, [0, 1, 0, 1, 0], [change, 0.0, 0, -.0])

Tags: csvthetoinimportlocationchangeyear