How to delete some of the mean weekly values calculated by pandas (.resample)?

Muhammad

I have a data set and needs to calculate daily average and weekly average. I know this can be done by Pandas. Below is the data and code that I have till now;

date                T1      T2      T3
12/17/13 00:28:38   19      23.1    7.3
12/17/13 00:58:38   19      22.9    7.3
12/17/13 01:28:38   18.9    22.8    6.3
12/17/13 01:58:38   18.9    23.1    6.3
12/17/13 02:28:38   18.8    23      6.3
12/17/13 02:58:38   18.8    22.9    6.3
.......
12/18/13 00:28:07   19.5    22.4    5.3
12/18/13 00:58:08   19.4    22.3    5.3
12/18/13 01:28:07   19.4    22.1    5.3
.......
3/22/14 16:55:18    17.7    20.6    10.1
3/22/14 17:08:31    17.7    20.6    10.1
3/22/14 17:26:04    17.6    20.5    8
3/22/14 17:56:04    17.7    20.5    7

and the code that I have till now is;

import pandas as pd
Temp=pd.read_csv("Book1.csv",parse_dates=['date'])  
Temp=Temp.set_index('date')
In [25]: Temp_plot.head()
Temp_plot=Temp.resample('W',how='mean')
Temp_plot.head()
Out[25]:
T1  T2  T3
date            
2013-12-22  18.740345   35.055517   7.532414
2013-12-29  14.501770   14.950442   6.497935
2014-01-05  13.135207   14.064793   7.795858
2014-01-12  17.296154   38.503550   7.827219
2014-01-19  18.217699   38.892625   6.952212

The problem is now I have to delete some mean weekly values that were holidays and should not be included in the resulted mean values. Shall I have one list that contains the dates that should not be included and then comparing values in the Temp_plot?

EDIT

I have added a list Wase = ["2013-12-22","2014-01-05"], as suggested in comments and used Temp_plot1 = Temp_plot.drop(Wase) Now I got any error, which says ValueError: labels ['2013-12-22' '2014-01-05'] not contained in axis. Any idea how to remove this error as I have to delete row that contains dates contain in list.

Alexander

You need to create a calendar of holidays using dt.date(year, month, day). Then you filter the holidays from the index using a list comprehension structure as shown below. Lastly, you select these filtered dates using .ix which selects data from a dataframe based on the index value.

import datetime as dt

holidays = [dt.date(2015, 12, 25), ...] 
idx = [timestamp for timestamp in Temp.index if timestamp.date() not in holidays]
Temp_plot = Temp.ix[idx].resample('W', how='mean')

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to disable calculating with nans while pandas resample().mean() and resample().sum()?

From Dev

Pandas - mean() on a weekly basis

From Dev

Pandas: Resample from weekly to daily with offset

From Dev

Calculate mean of calculated values

From Dev

Resample after rolling mean in pandas

From Dev

Mean of values in some columns with Pandas/Numpy

From Dev

Pandas Dataframe resample on ms values

From Dev

Pandas Resample does not work with mean() method

From Dev

Pandas: Use .resample() and .mean() with skipna=False

From Dev

Resample Python pandas exclude some fields

From Dev

how to delete nan values in pandas?

From Dev

How to resample a pandas dataframe to hourly mean, taking into account both a time and a column with a string value?

From Dev

How to delete observation where in some column values do not have certain number of numbers in Python Pandas?

From Dev

How to resample vector values in R?

From Dev

how to use pandas resample method?

From Dev

How to resample value in pandas column?

From Dev

How to groupby and resample data in pandas?

From Dev

Python Pandas - how delete some columns

From Dev

How to Delete Rows That Contains Some Text in Pandas

From Dev

How to resample pandas timeseries df into new rows representing equal cumsum of some measurement?

From Dev

Pandas: How to fill null values with mean of a groupby?

From Dev

How to fill nan values with rolling mean in pandas

From Python

how rank is calculated in pandas

From Dev

Pandas, group by resample and fill missing values with zero

From Dev

Resample 2d coordinates with values in pandas

From Dev

Pandas resample without dropping nan values

From Dev

Pandas: Count Unique Values after Resample

From Dev

How do you create a boxplot in seaborn with pre-calculated values for mean, median, percentile, etc?

From Dev

Resample hourly to daily and group by min, max and mean values

Related Related

  1. 1

    How to disable calculating with nans while pandas resample().mean() and resample().sum()?

  2. 2

    Pandas - mean() on a weekly basis

  3. 3

    Pandas: Resample from weekly to daily with offset

  4. 4

    Calculate mean of calculated values

  5. 5

    Resample after rolling mean in pandas

  6. 6

    Mean of values in some columns with Pandas/Numpy

  7. 7

    Pandas Dataframe resample on ms values

  8. 8

    Pandas Resample does not work with mean() method

  9. 9

    Pandas: Use .resample() and .mean() with skipna=False

  10. 10

    Resample Python pandas exclude some fields

  11. 11

    how to delete nan values in pandas?

  12. 12

    How to resample a pandas dataframe to hourly mean, taking into account both a time and a column with a string value?

  13. 13

    How to delete observation where in some column values do not have certain number of numbers in Python Pandas?

  14. 14

    How to resample vector values in R?

  15. 15

    how to use pandas resample method?

  16. 16

    How to resample value in pandas column?

  17. 17

    How to groupby and resample data in pandas?

  18. 18

    Python Pandas - how delete some columns

  19. 19

    How to Delete Rows That Contains Some Text in Pandas

  20. 20

    How to resample pandas timeseries df into new rows representing equal cumsum of some measurement?

  21. 21

    Pandas: How to fill null values with mean of a groupby?

  22. 22

    How to fill nan values with rolling mean in pandas

  23. 23

    how rank is calculated in pandas

  24. 24

    Pandas, group by resample and fill missing values with zero

  25. 25

    Resample 2d coordinates with values in pandas

  26. 26

    Pandas resample without dropping nan values

  27. 27

    Pandas: Count Unique Values after Resample

  28. 28

    How do you create a boxplot in seaborn with pre-calculated values for mean, median, percentile, etc?

  29. 29

    Resample hourly to daily and group by min, max and mean values

HotTag

Archive