<jupyter_start><jupyter_text>Fill in gaps in a time table<jupyter_code>import pandas as pd 


data = pd.read_csv("calls_server_across_time.csv").drop(["Unnamed: 0"], axis = 1)
data
df_org = data.copy(deep=True)
df_org['TimeGenerated'] = df_org['Time'].astype(object)

# Step 1: Convert Time to datetime object 
df_org.TimeGenerated = pd.to_datetime(df_org.TimeGenerated, format="%Y/%m/%d %H:%M:%S")

# Step 2: Create an index that goes from your minimum time to your maximum time and create a time 
# at the frequency you want. In our case, we want a new data point every minute => fre='min'
idx = pd.period_range(min(df_org.TimeGenerated), max(df_org.TimeGenerated), freq='min').strftime('%Y/%m/%d %H:%M:%S')
idx = pd.to_datetime(idx)

# Step 3: Build a dataframe based on this index 
df_date = pd.DataFrame()
df_date['TimeGenerated'] = idx

# Step 4: Merge this dataframe to your original dataset. If there is no point in your original dataset then
# you should expect to have an NA value in the merge. Those points are exactly the points where we have no failed 
# calls logged. Therefore we will NA values (~not failed calls) by a value of 0. 
df_merge = pd.merge(left = df_org, right = df_date, on='TimeGenerated', how = 'right').fillna(0)

df_merge = df_merge.loc[:, ['TimeGenerated', 'Calls']]
df_merge
# Save the above in a csv file 
df_merge.to_csv("calls_server_across_time_filled.csv", sep=",")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12195121951219512, 'fraction_numerical': 0.005574912891986063, 'mean_word_length': 5.243478260869566, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '396312', 'license': 'MIT', 'n_tokens_mistral': 490, 'n_tokens_neox': 479, 'n_words': 165, 'path': 'fill_time_gaps_Medium.ipynb', 'repo_name': 'MastafaF/PowerBI_Python_Medium_Part1', 'size': '1435'}