每次我尝试运行下面的代码时,输出文件将在最右边的列中显示错误的日期(12 AM-1:00时间的前一天)。有没有办法解决这个问题 - 我可以在代码中插入一个代码段来阻止它这样做?谢谢你的建议。
import pandas as pd
import datetime as dt
startDt = dt.datetime(2012,1,1)
endDt = dt.datetime.now()
#columns for dataframes
ListOfCol = ['TimeCET',
'TemperatureC',
'Dew PointC',
'Humidity',
'Sea Level PressurehPa',
'VisibilityKm',
'Wind Direction',
'Wind SpeedKm/h',
'Gust SpeedKm/h',
'PrecipitationCm',
'Events',
'Conditions',
'WindDirDegrees',
'Day'
]
for year in range(startDt.year,endDt.year+1):
for month in range(startDt.month,13):
if year < endDt.year: #means any remaining (future) days and months in the current year aren't included
url = 'http://www.wunderground.com/history/airport/LZIB/{:d}/{:d}/1/DailyHistory.html?format=1'.format(year,month)
elif month <= endDt.month: #means any remaining (future) days and months in the current year aren't included
url = 'http://www.wunderground.com/history/airport/LZIB/{:d}/{:d}/1/DailyHistory.html?format=1'.format(year,month)
else: #if current year and past current month leave as is
break
if year == startDt.year and month == startDt.month: #if first date for LZIB Airport create dataframe
BlavaDataFrame = pd.read_csv(url,comment='<',skiprows=1)
BlavaDataFrame.columns = ListOfCol
else: #if NOT first date for LZIB Airport append to dataframe to make long list of all data organized by date
BlavaDataFrameTEMP = pd.read_csv(url,comment='<',skiprows=1)
BlavaDataFrameTEMP.columns = ListOfCol
BlavaDataFrame = BlavaDataFrame.append(BlavaDataFrameTEMP,ignore_index=True)
BlavaDataFrame.to_csv('./LZIBhrs.csv')
print('Finished writing ./LZIBhrs.csv to disk')