This is my first question here, please pardon me if I make any mistakes.
I have two lists, List A and List B. List A has 'Date' associated with it, whereas, List B is a result of some calculations and it doesn't have any Date with it. The only thing common between these two is the column name (I have underlined it in the figures, they are not in ascending order though in List B), which is similar in both lists.
List A was the result of the following code:
number_of_columns = len(df.columns)
List_A= []
# loop over column indexes with step size 1
for i in range(0, number_of_columns, 1):
List_A.append(df.iloc[:, i][~np.isnan(df.iloc[:, i])])
And List B is the result of the following code:
def cusum(df, page_name):
pages = pd.unique(df['page_name']) #get all page names from df
master_df = pd.DataFrame()
dfs = []
for i in range(0,len(pages)):
S = [] #create empty cusum list
S.insert(0,0) #first entry to be zero
name_of_page = pages[i]
temp_df = df[(df.page_name == name_of_page)]
mean = temp_df['Engagement'].mean()
temp_df.reset_index(inplace=True)
Date = temp_df.Timestamp.values.astype(float)
for i in temp_df.index:
a = (S[i] + (temp_df['Engagement'][i] - mean))
S.append(round(a,3))
# S.extend(Date)
# master_df = pd.DataFrame({name_of_page:S})
del S[0]
dfs.append(pd.DataFrame({name_of_page:S}))
S.clear()
master_df = pd.concat(dfs, axis=1)
return dfs
List_B = []
List_B = cusum(original_df,'page_name')
And this is how my :original_df looks like
I would like to keep the Date from List A and values from List B based on the "names". Any guidance how can I do that?