Python:基于动态日期的DataFrame切片

时间:2020-05-17 14:19:35

标签: python dataframe slice

美好的一天,

我有一个简单的问题:我有一个包含各种列的DataFrame,索引是日期时间格式。现在,我想动态(使用循环)对DataFrame进行切片,就像我想每月处理每日数据一样。我如何格式化数据切片命令以使其可变?我知道groupby函数,但是我想对数据做更多的工作,据我了解,我只能对分组数据进行基本统计分析。

示例

public void onBindViewHolder(final ViewHolder holder, final int position) {
        if (conditionIsMet(getItem(position)) {
            holder.yourLayout.setBackgroundColor(Color.parseColor("#f6bcbc"));
        }
    }

我们的想法是对数据进行切片,使我获得每日收益,使用该每日数据进行一些分析,保存结果并移至下一个日历月。

因此,代码应该采用以下方式进行切片:

第一片:Daily_data = pd.read_excel('XXX.xlsx',sheet_name='Intra_month') Daily_data['Dates'] = pd.to_datetime(Daily_data['Dates']) Daily_data.set_index('Dates',inplace=True) for i in range(1999,2020): #i is supposed to be the year for r in range(0,11): #r is supposed to be the month Test_returns = Daily_data[...] #how can I make the slicing dynamic?

第二片:Test_returns = Daily_data['1999-01-01':'1999-01-31']

提前谢谢!

0 个答案:

没有答案
相关问题