gpt4 book ai didi

python - 将一个列表上的值分配给另一个列表

转载 作者:太空宇宙 更新时间:2023-11-03 20:03:56 24 4
gpt4 key购买 nike

我正在编写一个循环,从不同的工作表名称中提取数据,然后绘制这些数据。工作表名称在下面列出的代码中表示为“sheetnames”。每个工作表名称都与下面所示列表“ts”中的数字一起出现。当我绘制循环时,我需要 x 值是“ts”中与“sheetname”相对应的值。对于第一个,在将其放入循环之前,我可以在 x 值中放入“0”,但显然我不能再这样做了,因为第一张表的值仅为 0。我的完整代码很长,但下面是“sheetnames”、“ts”以及我的绘图的信息。请注意,sheetnames 中包含的数据只是我的代码从 Excel 文件中提取数据的工作表。如果需要更多信息,我可以使用其他代码进行更新。

sheetnames = ['0h UV Exposure, Roll Direction', 
'4h UV Exposure, Roll Direction',
'8h UV Exposure, Roll Direction',
'12h UV Exposure, Roll Direction',
'18h UV Exposure, Roll Direction',
'24h UV Exposure, Roll Direction',
'36h UV Exposure, Roll Direction',
'48h UV Exposure, Roll Direction',
'68h UV Exposure, Roll Direction',
'78h UV Exposure, Roll Direction',
'82h UV Exposure, Roll Direction',
'96h UV Exposure, Roll Direction']

ts = [0,4,8,12,18,24,36,48,68,78,82,96]

plt.figure()
plt.plot(0,Average_Toughness,'ro')
plt.xlabel('Time (Hours)')
plt.ylabel('Toughness')
plt.title('Toughness Plot')

最佳答案

您可以使用 range() 迭代列表 positions,然后访问当前位置,而不是直接迭代 sheetnames两个列表中的项目:

for pos in range(len(sheetnames)):
# now you can use sheetnames[pos] and ts[pos]

关于python - 将一个列表上的值分配给另一个列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59074672/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com