我不熟悉pandas,每周都要生成一个pivot表,使用csv作为源,其中包含几年来的记录。在
我想不出按周过滤数据帧的正确方法。这是我手动操作的方式:
fmindate = (df.fecha.astype( 'datetime64[ns]' ) >= pd.to_datetime( "2017-03-01" ))
fmaxdate = (df.fecha.astype( 'datetime64[ns]' ) <= pd.to_datetime( "2018-01-15" ))
dffiltered = df[ (fmindate & fmaxdate) ]
txt = pd.pivot_table(
dffiltered,
columns=[ "fecha" ],
index=[ "org", "tipo", "estado" ],
values=[ "destination", "time_total", "time_avg" ],
aggfunc={ "destination": len, "time_total": total_secs_inTimeSerie,
"time_avg": mean_secs_inTimeSerie },
fill_value="", margins=True
)
with open(report_name, "w") as text_file:
text_file.write ( txt.to_html() )
正确的方法是什么?在
提前非常感谢!在
您可以使用^{} :
^{pr2}$
也许我的解释不够清楚。从源csv我需要一个与我显示的完全一样的透视表,但是每个星期都有一个关于源记录的范围。 终于找到了解决办法,任何改进都是欢迎的。可能对其他人有用:
相关问题 更多 >
编程相关推荐