我希望通过特征分组将设备日期范围和特征的数据框转换为年度总安装时间。我想翻译一个像这样的数据框:
df_eq=pd.DataFrame({'equip':np.arange(0,10),'char1':[4]*4+[1,2,3]+[5]*3,
'char2':['A']*3+['B']*3+['C']*4,
'start':pd.to_datetime(['2010-01-10', '2010-01-10','2011-02-24','2011-06-06','2013-09-30','2010-01-10', '2010-01-10','2011-02-24','2011-06-06','2013-09-30']),
'end':pd.to_datetime(['2014-05-05']*2+['2015-01-01']*3+[None]*5)})
df_eq
char1 char2 end equip start
0 4 A 2014-05-05 0 2010-01-10
1 4 A 2014-05-05 1 2010-01-10
2 4 A 2015-01-01 2 2011-02-24
3 4 B 2015-01-01 3 2011-06-06
4 1 B 2015-01-01 4 2013-09-30
5 2 B NaT 5 2010-01-10
6 3 C NaT 6 2010-01-10
7 5 C NaT 7 2011-02-24
8 5 C NaT 8 2011-06-06
9 5 C NaT 9 2013-09-30
NaT
的{{1}}日期时间代表尚未退休的设备。使用这个数据框我想翻译产生以下样本,其中数量是给定年份内单位的安装时间:
end
我可以使用以下代码生成所需的表,但是我想看看是否有更多的pythonic方式使用pandas来生成相同的输出表:
char1 2011 2012 2013 2014
0 1 0.000000 0 0.254795 1.000000
1 2 1.000000 1 1.000000 1.000000
2 3 1.000000 1 1.000000 1.000000
3 4 3.424658 4 4.000000 2.684932
4 5 1.424658 2 2.254795 3.000000
char1 char2 2011 2012 2013 2014
0 1 B 0.000000 0 0.254795 1.000000
1 2 B 1.000000 1 1.000000 1.000000
2 3 C 1.000000 1 1.000000 1.000000
3 4 A 2.852055 3 3.000000 1.684932
4 4 B 0.572603 1 1.000000 1.000000
5 5 C 1.424658 2 2.254795 3.000000
答案 0 :(得分:1)
我认为您可以使用private void LoadDynamincVideoViews(final String path, String ID) {
final float scale = getApplicationContext().getResources()
.getDisplayMetrics().density;
int pixels = (int) (200 * scale + 0.5f);
int pixels1 = (int) (250 * scale + 0.5f);
int height = (Devicewidth * 9 / 16);
mVideoView = new VideoView(this);
mVideoView.setTag(ID);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
pixels, height);
params.setMargins(10, 5, 5, 5);
mVideoView.setLayoutParams(params);
mVideoViewArray.put(ID, mVideoView);
mLinearBottom.addView(mVideoView);
// HashMap< String, VideoView> hashmap = new HashMap<String,
// VideoView>();
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
MediaController mediaController = new MediaController(
getApplicationContext());
mediaController.setAnchorView(mVideoView);
// mediaController.setMediaPlayer(videoview);
Uri video = Uri.parse(path);
mVideoView.setMediaController(mediaController);
mVideoView.setVideoURI(video);
mVideoView.start();
}
}, 2000);
}
向您的部分代码进行矢量化,如下所示:
.where