我试图创建一些风数据的图表,但是,我很难使用两个参数(一天中的小时和月份)来选择特定的数据。我正在尝试使用一个函数来查找特定数据,但是却收到错误
Traceback (most recent call last):
File "/Users/Cpower18/Documents/Tryong_again.py", line 47, in <module>
plt.plot(hr, hdh(hr, mn2))
File "/Users/Cpower18/Documents/Tryong_again.py", line 37, in hdh
for n, k in hr, mn2:
ValueError: too many values to unpack (expected 2)
我目前正在使用数据框根据日期对数据进行排序,并使用一种功能来获取特定数据。我已经设法只使用一个变量,即一天中的小时,但是没有两个变量。
import csv
import warnings
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
warnings.simplefilter(action='ignore', category=FutureWarning)
data = pd.read_csv('merged_1.csv')
df = pd.DataFrame(data)
df['Wind Spd (km/h)'] = pd.to_numeric(df['Wind Spd (km/h)'], errors ='coerce')
df['Date/Time'] = pd.to_datetime(df['Date/Time'], errors = 'coerce')
df = df.set_index(pd.DatetimeIndex(df['Date/Time']))
df['hour'] = df.index.hour
df['month'] = df.index.month
mn1 = np.linspace(1, 2, 2)
mn2 = np.linspace(3, 5, 3)
mn3 = np.linspace(6, 8, 3)
mn4 = np.linspace(9, 11, 3)
mn5 = np.linspace(12)
hr = np.linspace(0, 23, 24)
def hdh(hr, mn2):
out = []
for n, k in hr, mn2:
t = (df['hour'] == n) & (df['month'] == k)
s = t['Wind Spd (km/h)'].mean(axis = 0) / 3.6
out.append(s)
return out
plt.plot(hr, hdh(hr, mn2))
plt.xlabel('Hour')
plt.ylabel('Wind Speed (m/s)')
plt.xlim(0, 24)
plt.ylim(2.85, 4.75)
plt.title('ShearENV Anual Average Hourly Wind Speed')
plt.grid(which = 'both', axis='both')
plt.show()`
预期结果应该是符合特定时间(例如01:00)和特定季节(例如3到5个月)的数据列表。到目前为止,我只是遇到错误,谢谢您的帮助。