pandas lookup daily series value for half-hour dataframe index
By : JoAnne Wickwire Lath
Date : March 29 2020, 07:55 AM
Does that help I have a pandas dataframe with a half-hour timeseries index and a series of daily data that I need to match based on date for an equation. The following code works using .get() in a loop but is slow and seems rather "unpythonic." , you can do this pandathonically: first, get the date-only field: code :
df_t['Date'] = pd.to_datetime(df_t.index.date)
df_t = df_t.reset_index().set_index('Date')
df_t['E'] = ts_d
df_t = df_t.reset_index().set_index('index')
df_t.ix[pd.to_datetime('20130102')]
|
what is the best way to merge pandas.Dataframe with pandas.Series based on df.columns and Series.index names?
By : Gambler
Date : March 29 2020, 07:55 AM
help you fix your problem Suppose that you create these series as outputs output_rms_1, output_rms_2, etc., than the series can be combined in one dataframe code :
import pandas as pd
dfRms = pd.DataFrame([output_rms_1, output_rms_2, output_rms_3])
dfRms = dfRms.append(output_rms_10, ignore_index=True)
result = pd.merge(wfm, dfRms, on=['CFN', 'OPN'], how='left')
|
how to count start hour of day, end hour of day, average hours per day in pandas dataframe?
By : user2894740
Date : March 29 2020, 07:55 AM
I hope this helps . I have a dataframe: , IIUC you can try this: code :
df['timestamps'] = pd.to_datetime(df['timestamps'])
df['hour'] = df['timestamps'].dt.hour
df.groupby(df['timestamps'].dt.day).agg({'hour': ['min', 'max', 'mean']}) \
.stack(level=0).droplevel(1)
min max mean
timestamps
18 20 20 20.000000
19 12 22 14.400000
20 10 12 11.166667
|
Pandas - Add values from series to dataframe column based on index of series matching some value in dataframe
By : user3531465
Date : March 29 2020, 07:55 AM
To fix this issue Data , I would use the second solution you propose or better this: code :
df['cost']=(df['mark_up_id'].map(pb['mark_up']) + df['cost']).fillna(df['cost'])
df.assign( Cost=(df['mark_up_id'].map(pb['mark_up']) + df['cost']).fillna(df['cost']) )
%%timeit
df['cost']=(df['mark_up_id'].map(pb['mark_up']) + df['cost']).fillna(df['cost'])
#945 µs ± 46 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
%%timeit
test = df.join(pb, on='mark_up_id', how='left')
test['cost'].update(test['cost'] + test['mark_up'])
test.drop('mark_up',axis=1,inplace=True)
#3.59 ms ± 137 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
%%timeit
df['cost'].update(df['mark_up_id'].map(pb['mark_up']) + df['cost'])
#985 µs ± 32.8 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
|
Python pandas: merge dataframe to series on series's index and dataframe's column
By : ColoradoJake1
Date : March 29 2020, 07:55 AM
help you fix your problem You got to add a few things: First, your counts_df has no column name, adding the name will get you a Dataframe with a column name code :
counts_df=pd.DataFrame({'Topic_Num':counts.index, 'value':counts.values})
merge = counts_df.merge(topicKeywordsDf, left_index=True, right_on="Topic_Num").drop_duplicates()
|