简体   繁体   English

用不相等的数据集绘制熊猫数据框

[英]plotting pandas data frame with unequal data set

I am trying to plot a pandas Data Frame that contain an unequal amount of data points (rows) and I am not sure if this is causing an issue for my plot. 我正在尝试绘制一个包含不相等数量的数据点(行)的熊猫数据框,并且不确定这是否会导致我的绘制问题。

in the below code, the portfolioValue# differs in length 在下面的代码中,PortfolioValue#的长度不同

portfolioValue1 = 521
portfolioValue1 = 500
portfolioValue1 = 521
portfolioValue1 = 521
portfolioValue1 = 425

my pandas data frame shape is 我的熊猫数据框形状是

(1, 5)

Here is the python code: 这是python代码:

portToPlot = {'AAPL.txt':[portfolioValue1], 'GOOG.txt':[portfolioValue2], 'MSFT.txt':[portfolioValue3],
    'AMZN.txt':[portfolioValue4],'CMG.txt':[portfolioValue5]}

portDFrame = DataFrame(portToPlot)

portDFrame.plot(sharex=True)

This is the error I keep getting 这是我不断得到的错误

return array(a, dtype, copy=False, order=order)
ValueError: setting an array element with a sequence.

They need to be of equal length, for example, we can shorten everything to 425 elements: 它们的长度必须相等,例如,我们可以将所有内容缩短为425个元素:

portfolioValue1 = random.random(521) 
portfolioValue2 = random.random(500) 
portfolioValue3 = random.random(521) 
portfolioValue4 = random.random(521) 
portfolioValue5 = random.random(425) 
portDFrame=DataFrame(zip(portfolioValue1,portfolioValue2,portfolioValue3,portfolioValue4,portfolioValue5))
portDFrame.columns=['AAPL.txt', 'GOOG.txt', 'MSFT.txt','AMZN.txt','CMG.txt']
portDFrame.plot(sharex=True)

在此处输入图片说明

But it looks to me that you are working on interday stock data for one year duration. 但在我看来,您正在处理一年中的日间股票数据。 I think the reason some of them are shorter is because there are missing interday price for some trading days. 我认为其中一些较短的原因是因为某些交易日缺少日内价格。 You should have preserved those missing data in the first place rather than just discard them altogether. 首先,您应该保留那些丢失的数据,而不是完全丢弃它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM