我有一个CSV文件,我想检查第一行是否只有字符串(即标题).我试图避免使用像熊猫等任何额外的东西.我想我会使用if语句,如果row [0]是字符串打印这是一个CSV,但我真的不知道如何做到这一点: - 任何建议?
我正在尝试使用Python上的PuLP 来解决这个问题http://www.me.utexas.edu/~jensen/ORMM/models/unit/linear/subunits/workforce/.
这是我的代码:
from pulp import *
# Create the 'prob' variable to contain the problem data
prob = LpProblem("The Bus Problem",LpMinimize)
# The variables are created with a lower limit of zero
x0=LpVariable("Number of drivers at time 0",0,None,LpInteger)
x4=LpVariable("Number of drivers at time 4",0)
x8=LpVariable("Number of drivers at time 8",0)
x12=LpVariable("Number of drivers at time 12",0)
x16=LpVariable("Number of drivers at time 16",0)
x20=LpVariable("Number of drivers at time 20",0)
# The objective function is added to 'prob' first …Run Code Online (Sandbox Code Playgroud) 我正在尝试生成一个元组列表,例如[('Client 0', 120),..,('Client 9', 45)],这是totalitems在代码中.我正在使用下面的代码,但是我收到了一个错误,我不确定为什么.
N = 10
value_range = np.arange(0, N, 1)
newitems = []
for i in value_range:
newvisits = ("Client %d" % i,) + random_tuple(length=6, values=(0, 15, 30, 45, 60))
newitems.append(newvisits)
totalitems = []
i = 0
for each_client in newitems:
i += 1
total = sum(each_client[1:])
newtotal = ("Client %d" % i,) + tuple(total)
totalitems.append(newtotals)
Run Code Online (Sandbox Code Playgroud)
我得到的错误是:
newtotals = ("Client %d" % i,) + tuple(total)
TypeError: 'int' object is not iterable
Run Code Online (Sandbox Code Playgroud)
我试图找到每个元组的总数totalitems …
我想创建一个随机的元组列表,其中每个元组的长度相同(例如6个),并由随机选择 values = [0, 15, 30, 45, 60].
一个示例解决方案是[(0, 30, 60, 0 , 15, 0)...(15, 45, 45, 0, 30, 60)].但是,我不想接受(0, 0, 0, 0, 0, 0)这个解决方案.