Resample different behaviour with agg and calling the function

Resample different behaviour with agg and calling the function

Content Index :

Resample different behaviour with agg and calling the function
Tag : pandas , By : Andrew Bailey
Date : December 05 2020, 12:18 PM

this will help The reason why agg isn't working is that resample('T') returns a groupby-like structure with groups being the minute-by-minute rows
>>> data.resample('T').groups
{Timestamp('1900-11-01 00:00:00', freq='T'): 1,
 Timestamp('1900-11-01 00:01:00', freq='T'): 1,
 Timestamp('1900-11-01 00:02:00', freq='T'): 1,
 Timestamp('1900-11-01 00:03:00', freq='T'): 1,
 Timestamp('1900-11-01 00:04:00', freq='T'): 1, ...
>>> data.resample('D').groups
{Timestamp('1900-11-01 00:00:00', freq='D'): 6,
 Timestamp('1900-11-02 00:00:00', freq='D'): 8,
 Timestamp('1900-11-03 00:00:00', freq='D'): 10}
>>> data.resample('D').agg({'id': 'ffill', 'action': lambda _: 'playing'})
                       id   action
1900-11-01 00:00:00  10.0  playing
1900-11-01 00:05:00  10.0      NaN
1900-11-01 00:25:00  10.0      NaN
1900-11-01 00:30:00  10.0      NaN
1900-11-01 00:55:00  10.0      NaN
1900-11-01 23:58:00  99.0      NaN
1900-11-02 00:00:00   NaN  playing
1900-11-02 00:40:00  99.0      NaN
1900-11-02 00:50:00  99.0      NaN
1900-11-03 00:00:00   NaN  playing
1900-11-03 00:05:00  10.0      NaN
1900-11-03 00:24:00  10.0      NaN
df = data.resample('T').first()
df['id'] = df['id'].ffill()
df['action'] = df['action'].fillna('playing')
                       id         action
1900-11-01 00:00:00  10.0    starts_game
1900-11-01 00:01:00  10.0        playing
1900-11-01 00:02:00  10.0        playing
1900-11-01 00:03:00  10.0        playing
1900-11-01 00:04:00  10.0        playing
1900-11-01 00:05:00  10.0  team_a_scores
1900-11-01 00:06:00  10.0        playing
1900-11-01 00:07:00  10.0        playing
>>> data.asfreq('T').agg({'id': 'ffill', 'action': lambda _: 'playing'})
                       id   action
1900-11-01 00:00:00  10.0  playing
1900-11-01 00:01:00  10.0  playing
1900-11-01 00:02:00  10.0  playing
1900-11-01 00:03:00  10.0  playing
1900-11-01 00:04:00  10.0  playing
df = data.asfreq('T')
df['id'] = df['id'].ffill()
df['action'] = df['action'].fillna('playing')

No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

GCC behaviour when calling a function with too many arguments

Tag : c , By : CSCI GOIN KILL ME
Date : March 29 2020, 07:55 AM
I wish this help you In C, writing void foo() means that foo takes an unspecified number of arguments.
To indicate that the function foo() should take no arguments, you should write void foo(void)

Weird behaviour in calling template function

Tag : cpp , By : Marcos de Carvalho
Date : March 29 2020, 07:55 AM
I wish this helpful for you Literals in C++ have type array of N constant char, and that will decay into pointer to constant char, which cannot be converted to char*. If you want to provide an overload for C style strings, you should do:
const char *Min(const char *a, const char *b)

How to fillna() with value 0 after calling resample?

Tag : python , By : antonio
Date : March 29 2020, 07:55 AM
I hope this helps you . Well, I don't get why the code above is not working and I'm going to wait for somebody to give a better answer than this but I just found
.replace(np.nan, 0)

Different behaviour with resample and asfreq in pandas

Tag : python , By : kakashi_
Date : March 29 2020, 07:55 AM
I hope this helps . Keep in mind that DF.resample() is a time-based groupby which must be followed by a reduction method on each of its groups.
So simply using this would only initialize the Resampler just like it happens when you call DF.rolling() method. Both behave similarly here:
df[['A', 'B']].resample('12H')
DatetimeIndexResampler [freq=<12 * Hours>, axis=0, closed=left, label=left, convention=start, base=0]
df[['A', 'B']].resample('12H').ffill().join(df['value'])
df1 = df.resample('12H').asfreq()
df1[['A','B']] = df1[['A','B']].fillna(method='ffill')

JavaScript promises behaviour: calling global function vs local function

Tag : javascript , By : merten
Date : March 29 2020, 07:55 AM
With these it helps You are providing a value instead of a function as a callback to .then and .catch. Provide a function and it should work.
const successFunc = msg => {
    console.log(`Success ${msg}`);

const failFunc = msg => {
    console.log(`Fail ${msg}`);

// create a promise object
// inside the promise object, there is a logic gate inside.
const promise = new Promise((resolve, reject) => {
    const a = 5;
    const b = 1;
    if (a > b) {
        // it will call the resolve function
    } else {
        // it will call the reject function

// // the promise object is activate and start when calling
// // this is actually an object chain promise.then(func).catch(func)
    .then(() => successFunc("calling successFun"))
    .catch((e) => failFunc("calling Fail Func"));

    .then(() => {
    .catch(() => {
.then(successFunc("calling successFun"))
.catch(failFunc("calling Fail Func"));
Related Posts Related QUESTIONS :
  • Pandas access first column with duplicate column names
  • Cannot open a csv file
  • Splitting value dataframe over multiple timeslots
  • Why does changing "Date" column to datetime ruin graph?
  • Datetime column coerced to int when setting with .loc and slice
  • analysis of groups in pandas dataframe
  • Pandas period(month) to last day of the month in YYYY-MM-DD format
  • How can I find index of rows just same as a array from a pandas dataframe?
  • Pandas identify # of items which generate 80 of sales
  • How to add return value from function into dataframe Column?
  • ValueError: key must be provided when HDF5 file contains multiple datasets while reading h5 file in pandas i am getting
  • How to use groupby on the following dataset
  • How to determine the end of a non-NaN series in pandas
  • Categorical variables usage in pandas for ANOVA and regression?
  • Pandas resample with percentage change
  • iLocation based boolean indexing on an integer type is not available
  • updating non-null values of a column via function
  • Select the last value in time after multiple groupings
  • How to add aggregated rows based on other rows in Pandas dataframe
  • How to search and find a syntax error and then correct the syntax by adding to the string?
  • Logic operation: Select two values from a column in a dataframe
  • apply custom function in numpy array
  • Pandas cut results in Nan values
  • Replacing values in a df with values from another df
  • Update a string in a column based on conditions from a function in a Pandas Dataframe
  • unable to change from object type to float64 in pandas
  • Get a new df with the mean values of other dfs
  • Pandas - Rank by sequence of appearance
  • Pandas read_csv error when file name starts with the letter f
  • Replacing values in pandas data frame
  • Trying to use apply on a groupby object to add a column to each group
  • Convert date format to string in Pandas
  • Create a column by comparing two pandas dataframes
  • after groupby, set subplots into plots next to each-other rather than in one plot
  • pandas melt dataframe according to time index
  • How do I group up data based off a dictionary key with list values?
  • convert pandas datetime field with NAT entries to date
  • join or merge or reshape dataframe based on two conditions
  • How do I interpolate a time series, when measurements are taken at irregular times
  • How to apply *multiple* functions to pandas groupby apply?
  • after groupby, using agg, how to get one element on condition of other columns
  • Using .apply vs subsets
  • Adding values of 2 columns based on a condition
  • Slicing of a Pandas Series when index elements are not default (doesn't start with 0)
  • Trying to group by but only specific rows based on their value
  • Python Pandas Where Condition Is Not Working
  • Reindexing to Add Date Indices Not Working as Expected
  • How to count percentage row by row with multi-index
  • Insert a list to row in pandas?
  • Pandas Count Number of On/Off Events and Duration
  • How to GroupBy this data in Pandas, Python?
  • How to remove one specific duplicate named column in columns of a dataframe?
  • How to make new cell based on appearance in dataframe cell
  • Finding chunks of consecutive non negative in a columns
  • How to create a partially filled column in pandas
  • Reshape pandas dataframe and work with columns
  • How to extract first digit of every value of a column of dataframe(df) to a new dataframe (df1)
  • Pandas fill missing values with groupby
  • Fill zeroes with increment of the max value
  • Pandas sort grouby groups by arbitrary condition on its contents
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com