python matplotlib 画两条折线图 其中一组数据有空值 如何处理?
import csv
from datetime import datetime
from matplotlib import pyplot as plt
filename = 'data.csv'
with open(filename) as f:
reader = csv.reader(f)
header_row = next(reader)
dates = []
temp1 = []
temp2 = []
for row in reader:
time = row[1] + '-' + row[2] + '-' + row[3]
current_date = datetime.strptime(time, "%Y-%m-%d")
dates.append(current_date)
tempm1 = int(float(row[7]))
temp1.append(tempm1)
tempm2 = int(row[28])
temp2.append(tempm2)
fig = plt.figure(dpi=128, figsize=(10,6))
plt.plot(dates, temp1, c='red')
plt.plot(dates, temp2, c='blue')
plt.show()
报错:
C:\Users\yo\AppData\Local\Programs\Python\Python37\python.exe F:/论文/data/compare/compare.py
Traceback (most recent call last):
File "F:/论文/data/compare/compare.py", line 26, in
tempm2 = int(row[28])
ValueError: invalid literal for int() with base 10: '20.075'
Process finished with exit code 1
试过if 不为空值处理,然后数据对不齐了
我想要如果是空值图上就不显示
数据是有小数的所以就用int float 处理
请各位大神帮忙 谢谢!