Skip to content
Snippets Groups Projects

17 meta data

Merged Shufei Du requested to merge 17_meta_data into main
All threads resolved!
Files
2
+ 25
0
import pandas as pd
"""we want to create a function that takes a dataframe and returns another dataframe with
multiple columns {activity, {meta data columns}}"""
class Meta_data:
def __init__(self,df:pd.DataFrame) -> None:
self.df=df
def add_meta_data(self)->pd.DataFrame:
columns_all=self.df.columns
meta_data=[]
for col in columns_all:
if col not in ["timestamp","case id","activity"]:
meta_data.append(col)
#meta_data_columns are the columns expect "timestamp" and "case_id"
#remove the case_id and timestamp columns in the dataframe
columns_all=["activity"] + meta_data
df_new=self.df[columns_all].copy()
# Group by the activity and get the first value for each group
aggregated_df_first = df_new.groupby("activity").first().reset_index()
return aggregated_df_first
\ No newline at end of file
Loading