gpt4 book ai didi

python - Pandas dataframe.plot() - 折线图 - 未为前两个索引绘制的系列值

转载 作者:太空宇宙 更新时间:2023-11-04 04:05:30 30 4
gpt4 key购买 nike

在附加图像(附加数据框和绘制的折线图快照)中 - 系列索引范围从 242.0 到 252.0,但缺少索引 242.0 和 243.0 的数据。这里有什么问题?

相关代码如下:

import re
import json as js
import matplotlib.pyplot as plt
import pandas as pd

def plot(collector, run_type, stat_type):
ax = plt.gca()
run_info = collector.series[run_type]['info']
dfs = []
ctr_str = 'Type {}'
ctr = 0
for var in run_info:
ctr += 1
if not re.search(stat_type, var):
continue
var_info = run_info[var]
try:
dfs.append(pd.DataFrame({var: var_info['data']}, index=var_info['runs']))
except:
print(var_info['data'])
print(var_info['runs'])
x=1
pd.concat(dfs, axis=1, sort=False).sort_index().plot(kind='line', ax=ax)
plt.show(block=True)

enter image description here

最佳答案

对于 243,值出现在整列(Type1、Type2 和 Type5)中只有一个值的那些列中,因此线图不会绘制这些线。对于 242,nan 似乎打破了该列的行。但是,您需要在绘图之前处理 Nan。

关于python - Pandas dataframe.plot() - 折线图 - 未为前两个索引绘制的系列值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57428881/

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