Python “如何修复”;ValueError:长度不匹配“;
我得到一个错误:Python “如何修复”;ValueError:长度不匹配“;,python,excel,pandas,Python,Excel,Pandas,我得到一个错误: ValueError: Length mismatch: Expected axis has 5 elements, new values have 6 elements 当我运行基本代码时: import matplotlib.pyplot as plt import numpy as np import pandas as pd READ = "C:\\Users\\Ashley\\Biotech Data Center 4.1.21.xlsx"
ValueError: Length mismatch: Expected axis has 5 elements, new values have 6
elements
当我运行基本代码时:
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
READ = "C:\\Users\\Ashley\\Biotech Data Center 4.1.21.xlsx"
stocks = "BHVN"
PipelineData = pd.read_excel(READ, sheet_name='Sheet1', header=None, index_col=0)
pipelinecolstitle = pd.read_excel(READ, sheet_name='Sheet1', header=None,nrows=1).values[0]
PipelineData.columns = pipelinecolstitle
colspipe= ['Catalyst']
tt = PipelineData[colspipe]
for i in stocks:
t = tt.loc[(PipelineData['Ticker']==i)]
print(t)
fig, ax = plt.subplots()
cols = ["Catalyst"]
axMain = plt.subplot(2,1,1)
table = plt.subplot(2,1,2, frameon=False)
axMain.plot([1,2,7])
table = ax.table(cellText=t, loc='upper center',colLabels=cols)
table.axis("off")
plt.show()
它似乎不喜欢index_col=0
如果我更改索引\u col=None,它会给我一个键错误:0此错误可能是由此赋值引起的
PipelineData.columns=pipelinecolstitle
,这意味着PipelineData的列数不等于pipelinecolstitle长度
检查是否
PipelineData.shape[1]==len(pipelinecolstitle)
请提供重现错误的示例数据。它们在6处相等。