答案 0 :(得分:0)
假设您要摆脱非小时列,一个解决方案是:
result = df.set_index('date')\
.filter(regex='^h')\
.stack()\
.to_frame()
# index values are now tuples such as (2018-01-01, 'h1')
result = result.set_index(result.index.map(
lambda idx: idx[0] + timedelta(hours=int(idx[1][1:]))
))
答案 1 :(得分:0)
下面的代码块创建一个具有两列的新DataFrame:
代码:
new_data=[]
for index,row in your_DataFrame.iterrows():
zone_id_date=str(row['zone_id'])+'_'+str(row['date'])
for hour in range(1,25):
ID=zone_id_date+'_h'+str(hour)
observation=row['h'+str(hour)]
new_row=[ID,observation]
new_data.append(new_row)
output_data=pandas.DataFrame(data=new_data, columns = ['ID', 'observation'])