Note that there are some explanatory texts on larger screens.

plurals
  1. POSplit pandas dataframe by custom weeks
    primarykey
    data
    text
    <p>Im working with a large pandas dataframe of the following format:</p> <pre><code>In [15]: data.info() &lt;class 'pandas.core.frame.DataFrame'&gt; DatetimeIndex: 2869438 entries, 2011-09-26 22:00:00.078000 to 2011-12-30 22:14:57.413000 Data columns (total 3 columns): Symbol 2869438 non-null values Price 2869438 non-null values Vol 2869438 non-null values dtypes: float64(1), int64(1), object(1) </code></pre> <p>I have been able to split this into conventional weeks using the following:</p> <pre><code>weeks = data.groupby(data.index.week) weeks.groups.keys() Out[19]: [39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52] </code></pre> <p>For this particular dataframe weeks are defined as <code>'Sun Mon Tue Wed Thu Fri'</code></p> <pre><code>from pandas.tseries.offsets import CustomBusinessDay weekmask = 'Sun Mon Tue Wed Thu Fri' bday = CustomBusinessDay(weekmask=weekmask) weeks = data.groupby(bday) </code></pre> <p>This gives me groups that are TimeStamp indexed and not by week number.</p> <p>This is probably not the best way to achieve this, can anyone offer alternative techniques?</p> <p>UPDATE:</p> <p>Here is the head and tail of the data set I'm using:</p> <pre><code>data.head() Symbol Price Vol DateTime 2011-09-26 22:00:00.078000 CLX11 81.48 1 2011-09-26 22:00:00.192000 CLX11 81.46 1 2011-09-26 22:00:00.343000 CLX11 81.47 1 2011-09-26 22:00:00.443000 CLX11 81.46 1 2011-09-26 22:00:00.443000 CLX11 81.45 4 data.tail() Symbol Price Vol DateTime 2011-12-30 22:14:40.877000 CLG12 99.05 1 2011-12-30 22:14:43.287000 CLG12 99.06 1 2011-12-30 22:14:55.165000 CLG12 99.04 1 2011-12-30 22:14:55.165000 CLG12 99.03 1 2011-12-30 22:14:57.413000 CLG12 99.06 3 </code></pre> <p>All I simply want todo is cut this data into weeks and write it out to CSV files, I can already do this for conventional weeks (Mon-Sun) but I now want to cut into weeks that are defined as Sun-Fri.</p> <p>Can anyone help with that? The use of <code>CustomBuisnessDay</code> may not be what I want although it does seem to fit the use case. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload