<jupyter_start><jupyter_text>Preprocess data into 15 intervals  Imports<jupyter_code>import pandas as pd
from os.path import join
import datetime

%matplotlib inline
pd.set_option("display.precision", 2)
PATH = join("data_preprocessed", "historia_przejazdow_2019-07.csv")
PATH
df = pd.read_csv(PATH, index_col=0, parse_dates=True)

df.head()
df['start_time']= pd.to_datetime(df['start_time']) 
df['end_time']= pd.to_datetime(df['end_time'])
df.head()<jupyter_output><empty_output><jupyter_text>Divide in intervals  Earliest rental<jupyter_code>start = df.start_time.min()
start = start.replace(hour=0, minute=0, second=0)
start<jupyter_output><empty_output><jupyter_text>Latest return<jupyter_code>end = df.end_time.max()
end = end.replace(hour=0, minute=0, second=0) + datetime.timedelta(days=1)

end
ranges = pd.date_range(start, end,freq='15T')
ranges
all_trips_in_all_intervals_df  = pd.DataFrame(columns=["interval_start", "interval_end", "rental_place", "return_place"])
all_trips_in_all_intervals_df   
for i in range(len(ranges)-1):
    interval_start, interval_end = ranges[i],ranges[i+1]
    
    interval_df = df[(df.start_time <= interval_end) & (df.end_time >= interval_start)]    
    
    
    interval_df["interval_start"] = interval_start
    interval_df["interval_end"] = interval_end
    
    all_trips_in_all_intervals_df = all_trips_in_all_intervals_df.append(interval_df[["interval_start", "interval_end", "rental_place", "return_place"]])
all_trips_in_all_intervals_df<jupyter_output><empty_output><jupyter_text>Group by rentsl/return place<jupyter_code>intervals_grouped_df = pd.DataFrame(columns=["interval_start", "interval_end", "number_of_trips", "rental_place", "return_place"])

intervals_grouped_df
for i in range(len(ranges)-1):
    interval_start, interval_end = ranges[i],ranges[i+1]
    
    interval_group_df = (all_trips_in_all_intervals_df[all_trips_in_all_intervals_df["interval_start"] == interval_start]).groupby(['rental_place', 'return_place'], as_index=False).count()

    interval_group_df = interval_group_df.rename(columns={"interval_start": "number_of_trips"})

    interval_group_df["interval_start"] = interval_start
    interval_group_df["interval_end"] = interval_end
    
    intervals_grouped_df = intervals_grouped_df.append(interval_group_df)
intervals_grouped_df<jupyter_output><empty_output><jupyter_text>Save to CSV<jupyter_code>intervals_grouped_df.to_csv(join("plik.csv"), index=False)
intervals_grouped_df.groupby(["interval_start", "interval_end"], as_index=False).count()["number_of_trips"].max()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12972972972972974, 'fraction_numerical': 0.00888030888030888, 'mean_word_length': 8.560885608856088, 'pattern_counts': {'":': 1, '<': 22, '<?xml version=': 0, '>': 22, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '47229', 'license': 'MIT', 'n_tokens_mistral': 971, 'n_tokens_neox': 957, 'n_words': 120, 'path': '15 Minutes Interval Parser.ipynb', 'repo_name': 'burnpiro/wod-bike-temporal-network', 'size': '2590'}