python - Python 值错误。发酵地块需要更多的工作
问题描述
我正在尝试编写一个程序,该程序从 excel 文件中获取列并绘制它们。该图有多个轴,是来自发酵的数据。我在绘图代码方面得到了帮助,但我无法让它与数据一起工作。python 是否将列作为字符串读取?代码如下:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
# with the given sample data
data = {'Time': [0, 1, 2, 3], 'Temp': [28.05, 29.0, 28.65, 27.04], 'Agit': [400, 397, 402, 430], 'DO': [71.0, 5.0, 5.5, 2.0], 'pH': [5.5, 5.2, 4.9, 4.75], 'GasFlow': [1.0, 1.02, 1.01, 1.05]}
df = pd.DataFrame(data)
# insert the name of the column as a string in brackets
Time = list(df['Time'])
pH = list(df['pH'])
DO = list(df['DO'])
Agit = list(df['Agit'])
GasFlow = list(df['GasFlow'])
Temp = list(df['Temp'])
In [5]:
#%% Writing data
time = [Time] # Hours
temperature = [Temp] # dC
agitation = [Agit] # rpm
DO = [DO] # %
pH = [pH] # pH
gas_flow = [GasFlow] #vvm
# Plot the data
fig, host = plt.subplots(figsize=(8,5)) # (width, height) in inches
p1, = host.plot(time, temperature, color=color1, label="Temperature")
和错误:
ValueError Traceback (most recent call last)
<ipython-input-5-97e016dc1996> in <module>
72 # Plot the data
73
---> 74 p1, = host.plot(time, temperature, color=color1, label="Temperature")
75
76 p2, = par1.plot(time, agitation, color=color2, label="Agitation")
ValueError: too many values to unpack (expected 1)
解决方案
您发布了大约 75 行来支持 5 行问题。请更新您的帖子。
问题很简单。 plot
返回组成图形的线列表。您的分配解包列表并将第一个元素分配给p1
,但不涵盖列表的其他元素。尾随的逗号指定您将只采用该一个元素,而不是将整个列表分配给p1
. 你打算用这个语句来完成什么?如果该列表包含除单个元素之外的任何内容,这将保证运行时错误。
p1, = host.plot(time, temperature, color=color1, label="Temperature")
推荐阅读
- java - 为什么 ThreadLocal 的 initialValue 不会增加我的变量?
- java - Eclipse 的 Package Explorer 树中的星号和加号是什么意思?
- android - 我正在尝试在 Android Native Activity 中使用 opengles 绘制形状。但是没有画出来
- kubernetes - K3S:如何通过 hub.docker.com 进行身份验证也拉取私有图像?
- javascript - 使用 MVC 的 JQueryFullCalendar
- xcode - 在 Xcode 12 中运行签名后脚本
- javascript - 获取相对于旋转 div 上 div 浏览器窗口的 x 和 y
- java - java.lang.Error:从 assets 文件夹中复制 SQLite 数据库中的数据库时出错
- java - 在 Eclipse 插件中加密敏感数据
- salesforce - Salesforce 沙盒中不提供社区选项