173 KiB
173 KiB
In [ ]:
import os
# Define the path to your folder in Google Drive
folder_path = '/content/drive/My Drive/Data/iOS/'
# List files in the directory (optional, to verify the files are there)
print(os.listdir(folder_path))['StepCount01.csv', 'StepCount05.csv', 'StepCount07.csv', 'StepCount09.csv', 'StepCount10.csv', 'StepCount02.csv', 'StepCount08.csv', 'StepCount06.csv', 'StepCount12.csv', 'StepCount03.csv', 'StepCount11.csv', 'StepCount04.csv', 'StepCount20.csv', 'StepCount15.csv', 'StepCount23.csv', 'StepCount17.csv', 'StepCount13.csv', 'StepCount22.csv', 'StepCount24.csv', 'StepCount19.csv', 'StepCount18.csv', 'StepCount14.csv', 'StepCount16.csv', 'StepCount21.csv', 'StepCount29.csv', 'StepCount25.csv', 'StepCount30.csv', 'StepCount26.csv', 'StepCount28.csv', 'StepCount27.csv', 'StepCount31.csv', 'StepCount33.csv', 'StepCount32.csv', 'StepCount34.csv', 'StepCount36.csv', 'StepCount39.csv', 'StepCount38.csv', 'StepCount37.csv', 'StepCount35.csv', 'StepCount42.csv', 'StepCount43.csv', 'StepCount44.csv', 'StepCount41.csv', 'StepCount45.csv', 'StepCount40.csv', 'StepCount46.csv']
In [ ]:
from google.colab import drive
drive.mount('/content/drive')Drive already mounted at /content/drive; to attempt to forcibly remount, call drive.mount("/content/drive", force_remount=True).
In [ ]:
!pip install openpyxl
# Install the openpyxl packageCollecting openpyxl Downloading openpyxl-3.1.5-py2.py3-none-any.whl.metadata (2.5 kB) Collecting et-xmlfile (from openpyxl) Downloading et_xmlfile-1.1.0-py3-none-any.whl.metadata (1.8 kB) Downloading openpyxl-3.1.5-py2.py3-none-any.whl (250 kB) [2K [90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━[0m [32m250.9/250.9 kB[0m [31m1.7 MB/s[0m eta [36m0:00:00[0m [?25hDownloading et_xmlfile-1.1.0-py3-none-any.whl (4.7 kB) Installing collected packages: et-xmlfile, openpyxl Successfully installed et-xmlfile-1.1.0 openpyxl-3.1.5
In [ ]:
import pandas as pd
def process_file(file_path, user_label):
# Load the dataset
df = pd.read_csv(file_path, delimiter=';')
# Step 1: Filter for iPhone devices
iphone_df = df[df['device'].str.contains('iPhone', na=False)] # Treat NaN as False
# Step 2: Select the desired columns
result = iphone_df[['startDate', 'endDate', 'value']]
# Step 3: Convert startDate to datetime
iphone_df['startDate'] = pd.to_datetime(iphone_df['startDate'], format='%Y-%m-%d %H:%M:%S %z')
# Step 4: Extract date and hour
iphone_df['date'] = iphone_df['startDate'].dt.date
iphone_df['hour'] = iphone_df['startDate'].dt.hour
# Step 5: Group by date and hour, then sum the values
hourly_sum = iphone_df.groupby(['date', 'hour'])['value'].sum().reset_index()
# Step 6: Pivot the data to get one row per day with 24 columns for each hour
pivot_table = hourly_sum.pivot(index='date', columns='hour', values='value').fillna(0)
# Step 7: Rename columns to reflect hours
pivot_table.columns = [f'Hour_{i}' for i in pivot_table.columns]
# Step 8: Reset index to have 'date' as a column instead of index
pivot_table.reset_index(inplace=True)
# Step 9: Add day of the week, month, and year columns
pivot_table['DayOfWeek'] = pd.to_datetime(pivot_table['date']).dt.day_name()
pivot_table['Month'] = pd.to_datetime(pivot_table['date']).dt.month
pivot_table['Year'] = pd.to_datetime(pivot_table['date']).dt.year
# Step 10: One-hot encode the 'DayOfWeek' column
pivot_table = pd.concat([pivot_table, pd.get_dummies(pivot_table['DayOfWeek'], prefix='DayOfWeek')], axis=1)
# Step 11: Convert hourly values to binary (True if > 0, else False)
for col in pivot_table.columns[1:25]: # Skip the 'date' column and focus on hours
pivot_table[col] = pivot_table[col].apply(lambda x: True if x > 0 else False)
# Step 12: Add 'user' column with the specified user label
pivot_table['user'] = user_label
# Print which file is currently being processed
print(file_path,user_label)
# Step 13: Drop the 'DayOfWeek' column
pivot_table.drop(columns=['DayOfWeek'], inplace=True)
return pivot_table
# List of files to skip
files_to_skip = {'StepCount06.csv','StepCount10.csv','StepCount12.csv', 'StepCount13.csv', 'StepCount15.csv', 'StepCount17.csv',
'StepCount18.csv', 'StepCount20.csv', 'StepCount24.csv','StepCount27.csv', 'StepCount31.csv','StepCount32.csv',
'StepCount42.csv', 'StepCount46.csv'}
# Generate file paths, skipping specified files
file_paths = [f'/content/drive/My Drive/Data/iOS/StepCount{i:02d}.csv' for i in range(1, 47)
if f'StepCount{i:02d}.csv' not in files_to_skip]
# Generate user labels based on file index
user_labels = list(range(len(file_paths)))
# Process each file with its corresponding user label and concatenate the results
processed_dfs = [process_file(file_path, user_label) for file_path, user_label in zip(file_paths, user_labels)]
combined_df = pd.concat(processed_dfs, ignore_index=True)
# Save the combined DataFrame to a new Excel file
updated_file_path = '/content/combined_aggregated_data.xlsx'
combined_df.to_excel(updated_file_path, index=False)
# Print the final DataFrame
print(combined_df)
<ipython-input-5-a4235d7882e2>:15: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy iphone_df['startDate'] = pd.to_datetime(iphone_df['startDate'], format='%Y-%m-%d %H:%M:%S %z') <ipython-input-5-a4235d7882e2>:18: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy iphone_df['date'] = iphone_df['startDate'].dt.date <ipython-input-5-a4235d7882e2>:19: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy iphone_df['hour'] = iphone_df['startDate'].dt.hour
/content/drive/My Drive/Data/iOS/StepCount01.csv 0
<ipython-input-5-a4235d7882e2>:15: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy iphone_df['startDate'] = pd.to_datetime(iphone_df['startDate'], format='%Y-%m-%d %H:%M:%S %z') <ipython-input-5-a4235d7882e2>:18: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy iphone_df['date'] = iphone_df['startDate'].dt.date <ipython-input-5-a4235d7882e2>:19: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy iphone_df['hour'] = iphone_df['startDate'].dt.hour
/content/drive/My Drive/Data/iOS/StepCount02.csv 1 /content/drive/My Drive/Data/iOS/StepCount03.csv 2 /content/drive/My Drive/Data/iOS/StepCount04.csv 3
<ipython-input-5-a4235d7882e2>:15: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy iphone_df['startDate'] = pd.to_datetime(iphone_df['startDate'], format='%Y-%m-%d %H:%M:%S %z') <ipython-input-5-a4235d7882e2>:18: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy iphone_df['date'] = iphone_df['startDate'].dt.date <ipython-input-5-a4235d7882e2>:19: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy iphone_df['hour'] = iphone_df['startDate'].dt.hour
/content/drive/My Drive/Data/iOS/StepCount05.csv 4
<ipython-input-5-a4235d7882e2>:15: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy iphone_df['startDate'] = pd.to_datetime(iphone_df['startDate'], format='%Y-%m-%d %H:%M:%S %z') <ipython-input-5-a4235d7882e2>:18: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy iphone_df['date'] = iphone_df['startDate'].dt.date <ipython-input-5-a4235d7882e2>:19: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy iphone_df['hour'] = iphone_df['startDate'].dt.hour
/content/drive/My Drive/Data/iOS/StepCount07.csv 5
<ipython-input-5-a4235d7882e2>:15: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy iphone_df['startDate'] = pd.to_datetime(iphone_df['startDate'], format='%Y-%m-%d %H:%M:%S %z') <ipython-input-5-a4235d7882e2>:18: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy iphone_df['date'] = iphone_df['startDate'].dt.date <ipython-input-5-a4235d7882e2>:19: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy iphone_df['hour'] = iphone_df['startDate'].dt.hour
/content/drive/My Drive/Data/iOS/StepCount08.csv 6 /content/drive/My Drive/Data/iOS/StepCount09.csv 7 /content/drive/My Drive/Data/iOS/StepCount11.csv 8 /content/drive/My Drive/Data/iOS/StepCount14.csv 9 /content/drive/My Drive/Data/iOS/StepCount16.csv 10 /content/drive/My Drive/Data/iOS/StepCount19.csv 11 /content/drive/My Drive/Data/iOS/StepCount21.csv 12 /content/drive/My Drive/Data/iOS/StepCount22.csv 13
<ipython-input-5-a4235d7882e2>:15: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy iphone_df['startDate'] = pd.to_datetime(iphone_df['startDate'], format='%Y-%m-%d %H:%M:%S %z') <ipython-input-5-a4235d7882e2>:18: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy iphone_df['date'] = iphone_df['startDate'].dt.date <ipython-input-5-a4235d7882e2>:19: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy iphone_df['hour'] = iphone_df['startDate'].dt.hour
/content/drive/My Drive/Data/iOS/StepCount23.csv 14
<ipython-input-5-a4235d7882e2>:15: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy iphone_df['startDate'] = pd.to_datetime(iphone_df['startDate'], format='%Y-%m-%d %H:%M:%S %z') <ipython-input-5-a4235d7882e2>:18: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy iphone_df['date'] = iphone_df['startDate'].dt.date <ipython-input-5-a4235d7882e2>:19: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy iphone_df['hour'] = iphone_df['startDate'].dt.hour
/content/drive/My Drive/Data/iOS/StepCount25.csv 15 /content/drive/My Drive/Data/iOS/StepCount26.csv 16
<ipython-input-5-a4235d7882e2>:15: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy iphone_df['startDate'] = pd.to_datetime(iphone_df['startDate'], format='%Y-%m-%d %H:%M:%S %z') <ipython-input-5-a4235d7882e2>:18: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy iphone_df['date'] = iphone_df['startDate'].dt.date <ipython-input-5-a4235d7882e2>:19: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy iphone_df['hour'] = iphone_df['startDate'].dt.hour
/content/drive/My Drive/Data/iOS/StepCount28.csv 17 /content/drive/My Drive/Data/iOS/StepCount29.csv 18 /content/drive/My Drive/Data/iOS/StepCount30.csv 19
<ipython-input-5-a4235d7882e2>:15: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy iphone_df['startDate'] = pd.to_datetime(iphone_df['startDate'], format='%Y-%m-%d %H:%M:%S %z') <ipython-input-5-a4235d7882e2>:18: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy iphone_df['date'] = iphone_df['startDate'].dt.date <ipython-input-5-a4235d7882e2>:19: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy iphone_df['hour'] = iphone_df['startDate'].dt.hour
/content/drive/My Drive/Data/iOS/StepCount33.csv 20 /content/drive/My Drive/Data/iOS/StepCount34.csv 21 /content/drive/My Drive/Data/iOS/StepCount35.csv 22 /content/drive/My Drive/Data/iOS/StepCount36.csv 23
<ipython-input-5-a4235d7882e2>:15: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy iphone_df['startDate'] = pd.to_datetime(iphone_df['startDate'], format='%Y-%m-%d %H:%M:%S %z') <ipython-input-5-a4235d7882e2>:18: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy iphone_df['date'] = iphone_df['startDate'].dt.date <ipython-input-5-a4235d7882e2>:19: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy iphone_df['hour'] = iphone_df['startDate'].dt.hour
/content/drive/My Drive/Data/iOS/StepCount37.csv 24
<ipython-input-5-a4235d7882e2>:15: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy iphone_df['startDate'] = pd.to_datetime(iphone_df['startDate'], format='%Y-%m-%d %H:%M:%S %z') <ipython-input-5-a4235d7882e2>:18: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy iphone_df['date'] = iphone_df['startDate'].dt.date <ipython-input-5-a4235d7882e2>:19: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy iphone_df['hour'] = iphone_df['startDate'].dt.hour
/content/drive/My Drive/Data/iOS/StepCount38.csv 25 /content/drive/My Drive/Data/iOS/StepCount39.csv 26
<ipython-input-5-a4235d7882e2>:15: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy iphone_df['startDate'] = pd.to_datetime(iphone_df['startDate'], format='%Y-%m-%d %H:%M:%S %z') <ipython-input-5-a4235d7882e2>:18: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy iphone_df['date'] = iphone_df['startDate'].dt.date <ipython-input-5-a4235d7882e2>:19: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy iphone_df['hour'] = iphone_df['startDate'].dt.hour
/content/drive/My Drive/Data/iOS/StepCount40.csv 27
<ipython-input-5-a4235d7882e2>:15: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy iphone_df['startDate'] = pd.to_datetime(iphone_df['startDate'], format='%Y-%m-%d %H:%M:%S %z') <ipython-input-5-a4235d7882e2>:18: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy iphone_df['date'] = iphone_df['startDate'].dt.date <ipython-input-5-a4235d7882e2>:19: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy iphone_df['hour'] = iphone_df['startDate'].dt.hour
/content/drive/My Drive/Data/iOS/StepCount41.csv 28
/content/drive/My Drive/Data/iOS/StepCount43.csv 29
/content/drive/My Drive/Data/iOS/StepCount44.csv 30
/content/drive/My Drive/Data/iOS/StepCount45.csv 31
date Hour_0 Hour_1 Hour_2 Hour_3 Hour_4 Hour_5 Hour_6 \
0 2017-07-20 False False False False False False False
1 2017-07-21 False False False False False False False
2 2017-07-22 True True False False False False False
3 2017-07-23 False False False False False False False
4 2017-07-24 True True False False False False False
... ... ... ... ... ... ... ... ...
36480 2020-06-09 True False False False False False False
36481 2020-06-10 False False True False False False False
36482 2020-06-11 True False False False False False True
36483 2020-06-12 True False False False False False False
36484 2020-06-13 True False False False False False False
Hour_7 Hour_8 ... Month Year DayOfWeek_Friday DayOfWeek_Monday \
0 False False ... 7 2017 False False
1 True True ... 7 2017 True False
2 True True ... 7 2017 False False
3 False True ... 7 2017 False False
4 False True ... 7 2017 False True
... ... ... ... ... ... ... ...
36480 False False ... 6 2020 False False
36481 False False ... 6 2020 False False
36482 True True ... 6 2020 False False
36483 False False ... 6 2020 True False
36484 False False ... 6 2020 False False
DayOfWeek_Saturday DayOfWeek_Sunday DayOfWeek_Thursday \
0 False False True
1 False False False
2 True False False
3 False True False
4 False False False
... ... ... ...
36480 False False False
36481 False False False
36482 False False True
36483 False False False
36484 True False False
DayOfWeek_Tuesday DayOfWeek_Wednesday user
0 False False 0
1 False False 0
2 False False 0
3 False False 0
4 False False 0
... ... ... ...
36480 True False 31
36481 False True 31
36482 False False 31
36483 False False 31
36484 False False 31
[36485 rows x 35 columns]
In [ ]:
import pandas as pd
import numpy as np
def process_file(file_path, user_label):
# Load the dataset
df = pd.read_csv(file_path, delimiter=';')
# Filter for iPhone devices
iphone_df = df[df['device'].str.contains('iPhone', na=False)]
# Convert startDate to datetime
iphone_df['startDate'] = pd.to_datetime(iphone_df['startDate'], format='%Y-%m-%d %H:%M:%S %z')
# Round down the startDate to the nearest 15-minute interval
iphone_df['15min_interval'] = iphone_df['startDate'].dt.floor('15T')
# Extract date, time, year, and month for 15-minute intervals
iphone_df['date'] = iphone_df['15min_interval'].dt.date
iphone_df['time'] = iphone_df['15min_interval'].dt.time
iphone_df['Year'] = iphone_df['15min_interval'].dt.year
iphone_df['Month'] = iphone_df['15min_interval'].dt.month
# Group by date, time, year, and month, then sum the values
interval_sum = iphone_df.groupby(['date', 'time', 'Year', 'Month'])['value'].sum().reset_index()
# Create a full range of 15-minute intervals (00:00:00 to 23:45:00)
full_time_range = pd.date_range('00:00', '23:45', freq='15T').time
# Pivot the data to get one row per day with columns for each 15-minute interval
pivot_table = interval_sum.pivot(index=['date', 'Year', 'Month'], columns='time', values='value').fillna(0)
# Reindex to include all possible 15-minute intervals
pivot_table = pivot_table.reindex(columns=full_time_range, fill_value=0)
# Rename columns to reflect 15-minute intervals
pivot_table.columns = [f'{str(col)}' for col in pivot_table.columns]
# Convert interval values to boolean (True if > 0, else False)
pivot_table = pivot_table.apply(lambda col: col != 0, axis=0)
# Reset index to have 'date', 'Year', and 'Month' as columns instead of index
pivot_table.reset_index(inplace=True)
# Add day of the week
pivot_table['DayOfWeek'] = pd.to_datetime(pivot_table['date']).dt.day_name()
# One-hot encode the 'DayOfWeek' column
pivot_table = pd.concat([pivot_table, pd.get_dummies(pivot_table['DayOfWeek'], prefix='DayOfWeek')], axis=1)
# Add a user column with the specified user label
pivot_table['user'] = user_label
# Print which file is currently being processed
print(f"Processing file: {file_path}, User label: {user_label}")
return pivot_table
# List of files to skip
files_to_skip = {'StepCount06.csv','StepCount10.csv','StepCount12.csv', 'StepCount13.csv', 'StepCount15.csv', 'StepCount17.csv',
'StepCount18.csv', 'StepCount20.csv', 'StepCount24.csv', 'StepCount27.csv','StepCount31.csv','StepCount32.csv',
'StepCount42.csv', 'StepCount46.csv'}
# Generate file paths, skipping specified files
file_paths = [f'/content/drive/My Drive/Data/iOS/StepCount{i:02d}.csv' for i in range(1, 47)
if f'StepCount{i:02d}.csv' not in files_to_skip]
# Generate user labels based on file index
user_labels = list(range(len(file_paths)))
# Process each file with its corresponding user label and concatenate the results
processed_dfs = [process_file(file_path, user_label) for file_path, user_label in zip(file_paths, user_labels)]
combined_df = pd.concat(processed_dfs, ignore_index=True)
# Save the combined DataFrame to a new Excel file
updated_file_path = '/content/combined_aggregated_data_15min_without_threshold.xlsx'
combined_df.to_excel(updated_file_path, index=False)
# Print the final DataFrame
print(combined_df)
<ipython-input-4-36a1c351e706>:12: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['startDate'] = pd.to_datetime(iphone_df['startDate'], format='%Y-%m-%d %H:%M:%S %z')
<ipython-input-4-36a1c351e706>:15: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['15min_interval'] = iphone_df['startDate'].dt.floor('15T')
<ipython-input-4-36a1c351e706>:18: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['date'] = iphone_df['15min_interval'].dt.date
<ipython-input-4-36a1c351e706>:19: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['time'] = iphone_df['15min_interval'].dt.time
<ipython-input-4-36a1c351e706>:20: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['Year'] = iphone_df['15min_interval'].dt.year
<ipython-input-4-36a1c351e706>:21: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['Month'] = iphone_df['15min_interval'].dt.month
Processing file: /content/drive/My Drive/Data/iOS/StepCount01.csv, User label: 0
<ipython-input-4-36a1c351e706>:12: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['startDate'] = pd.to_datetime(iphone_df['startDate'], format='%Y-%m-%d %H:%M:%S %z')
<ipython-input-4-36a1c351e706>:15: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['15min_interval'] = iphone_df['startDate'].dt.floor('15T')
<ipython-input-4-36a1c351e706>:18: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['date'] = iphone_df['15min_interval'].dt.date
<ipython-input-4-36a1c351e706>:19: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['time'] = iphone_df['15min_interval'].dt.time
<ipython-input-4-36a1c351e706>:20: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['Year'] = iphone_df['15min_interval'].dt.year
<ipython-input-4-36a1c351e706>:21: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['Month'] = iphone_df['15min_interval'].dt.month
Processing file: /content/drive/My Drive/Data/iOS/StepCount02.csv, User label: 1 Processing file: /content/drive/My Drive/Data/iOS/StepCount03.csv, User label: 2 Processing file: /content/drive/My Drive/Data/iOS/StepCount04.csv, User label: 3
<ipython-input-4-36a1c351e706>:12: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['startDate'] = pd.to_datetime(iphone_df['startDate'], format='%Y-%m-%d %H:%M:%S %z')
<ipython-input-4-36a1c351e706>:15: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['15min_interval'] = iphone_df['startDate'].dt.floor('15T')
<ipython-input-4-36a1c351e706>:18: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['date'] = iphone_df['15min_interval'].dt.date
<ipython-input-4-36a1c351e706>:19: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['time'] = iphone_df['15min_interval'].dt.time
<ipython-input-4-36a1c351e706>:20: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['Year'] = iphone_df['15min_interval'].dt.year
<ipython-input-4-36a1c351e706>:21: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['Month'] = iphone_df['15min_interval'].dt.month
Processing file: /content/drive/My Drive/Data/iOS/StepCount05.csv, User label: 4
<ipython-input-4-36a1c351e706>:12: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['startDate'] = pd.to_datetime(iphone_df['startDate'], format='%Y-%m-%d %H:%M:%S %z')
<ipython-input-4-36a1c351e706>:15: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['15min_interval'] = iphone_df['startDate'].dt.floor('15T')
<ipython-input-4-36a1c351e706>:18: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['date'] = iphone_df['15min_interval'].dt.date
<ipython-input-4-36a1c351e706>:19: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['time'] = iphone_df['15min_interval'].dt.time
<ipython-input-4-36a1c351e706>:20: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['Year'] = iphone_df['15min_interval'].dt.year
<ipython-input-4-36a1c351e706>:21: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['Month'] = iphone_df['15min_interval'].dt.month
Processing file: /content/drive/My Drive/Data/iOS/StepCount07.csv, User label: 5
<ipython-input-4-36a1c351e706>:12: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['startDate'] = pd.to_datetime(iphone_df['startDate'], format='%Y-%m-%d %H:%M:%S %z')
<ipython-input-4-36a1c351e706>:15: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['15min_interval'] = iphone_df['startDate'].dt.floor('15T')
<ipython-input-4-36a1c351e706>:18: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['date'] = iphone_df['15min_interval'].dt.date
<ipython-input-4-36a1c351e706>:19: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['time'] = iphone_df['15min_interval'].dt.time
<ipython-input-4-36a1c351e706>:20: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['Year'] = iphone_df['15min_interval'].dt.year
<ipython-input-4-36a1c351e706>:21: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['Month'] = iphone_df['15min_interval'].dt.month
Processing file: /content/drive/My Drive/Data/iOS/StepCount08.csv, User label: 6 Processing file: /content/drive/My Drive/Data/iOS/StepCount09.csv, User label: 7 Processing file: /content/drive/My Drive/Data/iOS/StepCount11.csv, User label: 8 Processing file: /content/drive/My Drive/Data/iOS/StepCount14.csv, User label: 9 Processing file: /content/drive/My Drive/Data/iOS/StepCount16.csv, User label: 10 Processing file: /content/drive/My Drive/Data/iOS/StepCount19.csv, User label: 11 Processing file: /content/drive/My Drive/Data/iOS/StepCount21.csv, User label: 12 Processing file: /content/drive/My Drive/Data/iOS/StepCount22.csv, User label: 13
<ipython-input-4-36a1c351e706>:12: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['startDate'] = pd.to_datetime(iphone_df['startDate'], format='%Y-%m-%d %H:%M:%S %z')
<ipython-input-4-36a1c351e706>:15: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['15min_interval'] = iphone_df['startDate'].dt.floor('15T')
<ipython-input-4-36a1c351e706>:18: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['date'] = iphone_df['15min_interval'].dt.date
<ipython-input-4-36a1c351e706>:19: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['time'] = iphone_df['15min_interval'].dt.time
<ipython-input-4-36a1c351e706>:20: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['Year'] = iphone_df['15min_interval'].dt.year
<ipython-input-4-36a1c351e706>:21: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['Month'] = iphone_df['15min_interval'].dt.month
Processing file: /content/drive/My Drive/Data/iOS/StepCount23.csv, User label: 14
<ipython-input-4-36a1c351e706>:12: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['startDate'] = pd.to_datetime(iphone_df['startDate'], format='%Y-%m-%d %H:%M:%S %z')
<ipython-input-4-36a1c351e706>:15: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['15min_interval'] = iphone_df['startDate'].dt.floor('15T')
<ipython-input-4-36a1c351e706>:18: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['date'] = iphone_df['15min_interval'].dt.date
<ipython-input-4-36a1c351e706>:19: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['time'] = iphone_df['15min_interval'].dt.time
<ipython-input-4-36a1c351e706>:20: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['Year'] = iphone_df['15min_interval'].dt.year
<ipython-input-4-36a1c351e706>:21: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['Month'] = iphone_df['15min_interval'].dt.month
Processing file: /content/drive/My Drive/Data/iOS/StepCount25.csv, User label: 15 Processing file: /content/drive/My Drive/Data/iOS/StepCount26.csv, User label: 16
<ipython-input-4-36a1c351e706>:12: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['startDate'] = pd.to_datetime(iphone_df['startDate'], format='%Y-%m-%d %H:%M:%S %z')
<ipython-input-4-36a1c351e706>:15: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['15min_interval'] = iphone_df['startDate'].dt.floor('15T')
<ipython-input-4-36a1c351e706>:18: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['date'] = iphone_df['15min_interval'].dt.date
<ipython-input-4-36a1c351e706>:19: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['time'] = iphone_df['15min_interval'].dt.time
<ipython-input-4-36a1c351e706>:20: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['Year'] = iphone_df['15min_interval'].dt.year
<ipython-input-4-36a1c351e706>:21: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['Month'] = iphone_df['15min_interval'].dt.month
Processing file: /content/drive/My Drive/Data/iOS/StepCount28.csv, User label: 17 Processing file: /content/drive/My Drive/Data/iOS/StepCount29.csv, User label: 18 Processing file: /content/drive/My Drive/Data/iOS/StepCount30.csv, User label: 19
<ipython-input-4-36a1c351e706>:12: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['startDate'] = pd.to_datetime(iphone_df['startDate'], format='%Y-%m-%d %H:%M:%S %z')
<ipython-input-4-36a1c351e706>:15: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['15min_interval'] = iphone_df['startDate'].dt.floor('15T')
<ipython-input-4-36a1c351e706>:18: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['date'] = iphone_df['15min_interval'].dt.date
<ipython-input-4-36a1c351e706>:19: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['time'] = iphone_df['15min_interval'].dt.time
<ipython-input-4-36a1c351e706>:20: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['Year'] = iphone_df['15min_interval'].dt.year
<ipython-input-4-36a1c351e706>:21: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['Month'] = iphone_df['15min_interval'].dt.month
Processing file: /content/drive/My Drive/Data/iOS/StepCount33.csv, User label: 20 Processing file: /content/drive/My Drive/Data/iOS/StepCount34.csv, User label: 21 Processing file: /content/drive/My Drive/Data/iOS/StepCount35.csv, User label: 22 Processing file: /content/drive/My Drive/Data/iOS/StepCount36.csv, User label: 23
<ipython-input-4-36a1c351e706>:12: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['startDate'] = pd.to_datetime(iphone_df['startDate'], format='%Y-%m-%d %H:%M:%S %z')
<ipython-input-4-36a1c351e706>:15: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['15min_interval'] = iphone_df['startDate'].dt.floor('15T')
<ipython-input-4-36a1c351e706>:18: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['date'] = iphone_df['15min_interval'].dt.date
<ipython-input-4-36a1c351e706>:19: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['time'] = iphone_df['15min_interval'].dt.time
<ipython-input-4-36a1c351e706>:20: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['Year'] = iphone_df['15min_interval'].dt.year
<ipython-input-4-36a1c351e706>:21: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['Month'] = iphone_df['15min_interval'].dt.month
Processing file: /content/drive/My Drive/Data/iOS/StepCount37.csv, User label: 24
<ipython-input-4-36a1c351e706>:12: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['startDate'] = pd.to_datetime(iphone_df['startDate'], format='%Y-%m-%d %H:%M:%S %z')
<ipython-input-4-36a1c351e706>:15: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['15min_interval'] = iphone_df['startDate'].dt.floor('15T')
<ipython-input-4-36a1c351e706>:18: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['date'] = iphone_df['15min_interval'].dt.date
<ipython-input-4-36a1c351e706>:19: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['time'] = iphone_df['15min_interval'].dt.time
<ipython-input-4-36a1c351e706>:20: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['Year'] = iphone_df['15min_interval'].dt.year
<ipython-input-4-36a1c351e706>:21: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['Month'] = iphone_df['15min_interval'].dt.month
Processing file: /content/drive/My Drive/Data/iOS/StepCount38.csv, User label: 25 Processing file: /content/drive/My Drive/Data/iOS/StepCount39.csv, User label: 26
<ipython-input-4-36a1c351e706>:12: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['startDate'] = pd.to_datetime(iphone_df['startDate'], format='%Y-%m-%d %H:%M:%S %z')
<ipython-input-4-36a1c351e706>:15: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['15min_interval'] = iphone_df['startDate'].dt.floor('15T')
<ipython-input-4-36a1c351e706>:18: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['date'] = iphone_df['15min_interval'].dt.date
<ipython-input-4-36a1c351e706>:19: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['time'] = iphone_df['15min_interval'].dt.time
<ipython-input-4-36a1c351e706>:20: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['Year'] = iphone_df['15min_interval'].dt.year
<ipython-input-4-36a1c351e706>:21: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['Month'] = iphone_df['15min_interval'].dt.month
Processing file: /content/drive/My Drive/Data/iOS/StepCount40.csv, User label: 27
<ipython-input-4-36a1c351e706>:12: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['startDate'] = pd.to_datetime(iphone_df['startDate'], format='%Y-%m-%d %H:%M:%S %z')
<ipython-input-4-36a1c351e706>:15: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['15min_interval'] = iphone_df['startDate'].dt.floor('15T')
<ipython-input-4-36a1c351e706>:18: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['date'] = iphone_df['15min_interval'].dt.date
<ipython-input-4-36a1c351e706>:19: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['time'] = iphone_df['15min_interval'].dt.time
<ipython-input-4-36a1c351e706>:20: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['Year'] = iphone_df['15min_interval'].dt.year
<ipython-input-4-36a1c351e706>:21: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['Month'] = iphone_df['15min_interval'].dt.month
Processing file: /content/drive/My Drive/Data/iOS/StepCount41.csv, User label: 28
Processing file: /content/drive/My Drive/Data/iOS/StepCount43.csv, User label: 29
Processing file: /content/drive/My Drive/Data/iOS/StepCount44.csv, User label: 30
Processing file: /content/drive/My Drive/Data/iOS/StepCount45.csv, User label: 31
date Year Month 00:00:00 00:15:00 00:30:00 00:45:00 \
0 2017-07-20 2017 7 False False False False
1 2017-07-21 2017 7 False False False False
2 2017-07-22 2017 7 False False False True
3 2017-07-23 2017 7 False False False False
4 2017-07-24 2017 7 False True False False
... ... ... ... ... ... ... ...
36480 2020-06-09 2020 6 False False True False
36481 2020-06-10 2020 6 False False False False
36482 2020-06-11 2020 6 False True False False
36483 2020-06-12 2020 6 False False True False
36484 2020-06-13 2020 6 False False True False
01:00:00 01:15:00 01:30:00 ... 23:45:00 DayOfWeek \
0 False False False ... False Thursday
1 False False False ... False Friday
2 True False False ... False Saturday
3 False False False ... False Sunday
4 False False True ... False Monday
... ... ... ... ... ... ...
36480 False False False ... False Tuesday
36481 False False False ... False Wednesday
36482 False False False ... False Thursday
36483 False False False ... False Friday
36484 False False False ... False Saturday
DayOfWeek_Friday DayOfWeek_Monday DayOfWeek_Saturday \
0 False False False
1 True False False
2 False False True
3 False False False
4 False True False
... ... ... ...
36480 False False False
36481 False False False
36482 False False False
36483 True False False
36484 False False True
DayOfWeek_Sunday DayOfWeek_Thursday DayOfWeek_Tuesday \
0 False True False
1 False False False
2 False False False
3 True False False
4 False False False
... ... ... ...
36480 False False True
36481 False False False
36482 False True False
36483 False False False
36484 False False False
DayOfWeek_Wednesday user
0 False 0
1 False 0
2 False 0
3 False 0
4 False 0
... ... ...
36480 False 31
36481 True 31
36482 False 31
36483 False 31
36484 False 31
[36485 rows x 108 columns]
In [ ]:
user_counts = combined_df['user'].value_counts()
# Display the count of each user
print(user_counts.sort_index())user 0 1025 1 1713 2 796 3 889 4 1656 5 498 6 880 7 1094 8 954 9 1657 10 1584 11 1561 12 1513 13 802 14 1388 15 1058 16 782 17 1155 18 810 19 1112 20 1555 21 1362 22 656 23 1289 24 829 25 1623 26 568 27 1621 28 1154 29 664 30 976 31 1261 Name: count, dtype: int64
In [ ]:
import pandas as pd
def process_file(file_path, user_label):
# Load the dataset
df = pd.read_csv(file_path, delimiter=';')
# Step 1: Filter for iPhone devices
iphone_df = df[df['device'].str.contains('iPhone', na=False)] # Treat NaN as False
# Step 2: Select the desired columns
result = iphone_df[['startDate', 'endDate', 'value']]
# Step 3: Convert startDate to datetime
iphone_df['startDate'] = pd.to_datetime(iphone_df['startDate'], format='%Y-%m-%d %H:%M:%S %z')
# Step 4: Round down the startDate to the nearest 15-minute interval
iphone_df['15min_interval'] = iphone_df['startDate'].dt.floor('15T')
# Step 5: Extract date and time
iphone_df['date'] = iphone_df['15min_interval'].dt.date
iphone_df['time'] = iphone_df['15min_interval'].dt.time
# Step 6: Group by date and time, then sum the values for 15-minute intervals
iphone_df_filtered = iphone_df[iphone_df['value'] > 25].dropna(subset=['value'])
interval_sum = iphone_df.groupby(['date', 'time'])['value'].sum().reset_index()
# Step 7: Pivot the data to get one row per day with columns for each 15-minute interval
pivot_table = interval_sum.pivot(index='date', columns='time', values='value').fillna(0)
# Step 8: Create a full range of 15-minute intervals (00:00:00 to 23:45:00)
full_time_range = pd.date_range('00:00', '23:45', freq='15T').time
# Step 9: Reindex to include all possible 15-minute intervals and fill missing values with 0
pivot_table = pivot_table.reindex(columns=full_time_range, fill_value=0)
# Step 10: Rename columns to reflect 15-minute intervals
pivot_table.columns = [f'{str(col)}' for col in pivot_table.columns]
# Step 11: Reset index to have 'date' as a column instead of an index
pivot_table.reset_index(inplace=True)
# Step 12: Add day of the week, month, and year columns
pivot_table['DayOfWeek'] = pd.to_datetime(pivot_table['date']).dt.day_name()
pivot_table['Month'] = pd.to_datetime(pivot_table['date']).dt.month
pivot_table['Year'] = pd.to_datetime(pivot_table['date']).dt.year
# Step 13: One-hot encode the 'DayOfWeek' column
pivot_table = pd.concat([pivot_table, pd.get_dummies(pivot_table['DayOfWeek'], prefix='DayOfWeek')], axis=1)
# Step 14: Convert 15-minute interval values to binary (True if > 0, else False)
for col in pivot_table.columns[1:97]: # Skip the 'date' column and focus on 15-minute intervals
pivot_table[col] = pivot_table[col].apply(lambda x: True if x > 0 else False)
# Step 15: Add 'user' column with the specified user label
pivot_table['user'] = user_label
# Print which file is currently being processed
print(f"Processing file: {file_path}, User label: {user_label}")
# Step 16: Drop the 'DayOfWeek' column as it has been one-hot encoded
pivot_table.drop(columns=['DayOfWeek'], inplace=True)
return pivot_table
# List of files to skip
files_to_skip = {'StepCount06.csv','StepCount10.csv','StepCount12.csv', 'StepCount13.csv', 'StepCount15.csv', 'StepCount17.csv',
'StepCount18.csv', 'StepCount20.csv', 'StepCount24.csv', 'StepCount27.csv','StepCount31.csv','StepCount32.csv',
'StepCount42.csv', 'StepCount46.csv'}
# Generate file paths, skipping specified files
file_paths = [f'/content/drive/My Drive/Data/iOS/StepCount{i:02d}.csv' for i in range(1, 47)
if f'StepCount{i:02d}.csv' not in files_to_skip]
# Generate user labels based on file index
user_labels = list(range(len(file_paths)))
# Process each file with its corresponding user label and concatenate the results
processed_dfs = [process_file(file_path, user_label) for file_path, user_label in zip(file_paths, user_labels)]
combined_df = pd.concat(processed_dfs, ignore_index=True)
# Save the combined DataFrame to a new Excel file
updated_file_path = '/content/combined_aggregated_data_15min_with_threshold.xlsx'
combined_df.to_excel(updated_file_path, index=False)
# Print the final DataFrame
print(combined_df)
<ipython-input-7-a477c39a373a>:14: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['startDate'] = pd.to_datetime(iphone_df['startDate'], format='%Y-%m-%d %H:%M:%S %z')
<ipython-input-7-a477c39a373a>:17: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['15min_interval'] = iphone_df['startDate'].dt.floor('15T')
<ipython-input-7-a477c39a373a>:20: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['date'] = iphone_df['15min_interval'].dt.date
<ipython-input-7-a477c39a373a>:21: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['time'] = iphone_df['15min_interval'].dt.time
Processing file: /content/drive/My Drive/Data/iOS/StepCount01.csv, User label: 0
<ipython-input-7-a477c39a373a>:14: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['startDate'] = pd.to_datetime(iphone_df['startDate'], format='%Y-%m-%d %H:%M:%S %z')
<ipython-input-7-a477c39a373a>:17: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['15min_interval'] = iphone_df['startDate'].dt.floor('15T')
<ipython-input-7-a477c39a373a>:20: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['date'] = iphone_df['15min_interval'].dt.date
<ipython-input-7-a477c39a373a>:21: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['time'] = iphone_df['15min_interval'].dt.time
Processing file: /content/drive/My Drive/Data/iOS/StepCount02.csv, User label: 1 Processing file: /content/drive/My Drive/Data/iOS/StepCount03.csv, User label: 2 Processing file: /content/drive/My Drive/Data/iOS/StepCount04.csv, User label: 3
<ipython-input-7-a477c39a373a>:14: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['startDate'] = pd.to_datetime(iphone_df['startDate'], format='%Y-%m-%d %H:%M:%S %z')
<ipython-input-7-a477c39a373a>:17: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['15min_interval'] = iphone_df['startDate'].dt.floor('15T')
<ipython-input-7-a477c39a373a>:20: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['date'] = iphone_df['15min_interval'].dt.date
<ipython-input-7-a477c39a373a>:21: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['time'] = iphone_df['15min_interval'].dt.time
Processing file: /content/drive/My Drive/Data/iOS/StepCount05.csv, User label: 4 Processing file: /content/drive/My Drive/Data/iOS/StepCount07.csv, User label: 5
<ipython-input-7-a477c39a373a>:14: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['startDate'] = pd.to_datetime(iphone_df['startDate'], format='%Y-%m-%d %H:%M:%S %z')
<ipython-input-7-a477c39a373a>:17: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['15min_interval'] = iphone_df['startDate'].dt.floor('15T')
<ipython-input-7-a477c39a373a>:20: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['date'] = iphone_df['15min_interval'].dt.date
<ipython-input-7-a477c39a373a>:21: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['time'] = iphone_df['15min_interval'].dt.time
<ipython-input-7-a477c39a373a>:14: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['startDate'] = pd.to_datetime(iphone_df['startDate'], format='%Y-%m-%d %H:%M:%S %z')
<ipython-input-7-a477c39a373a>:17: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['15min_interval'] = iphone_df['startDate'].dt.floor('15T')
<ipython-input-7-a477c39a373a>:20: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['date'] = iphone_df['15min_interval'].dt.date
<ipython-input-7-a477c39a373a>:21: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['time'] = iphone_df['15min_interval'].dt.time
Processing file: /content/drive/My Drive/Data/iOS/StepCount08.csv, User label: 6 Processing file: /content/drive/My Drive/Data/iOS/StepCount09.csv, User label: 7 Processing file: /content/drive/My Drive/Data/iOS/StepCount11.csv, User label: 8 Processing file: /content/drive/My Drive/Data/iOS/StepCount14.csv, User label: 9 Processing file: /content/drive/My Drive/Data/iOS/StepCount16.csv, User label: 10 Processing file: /content/drive/My Drive/Data/iOS/StepCount19.csv, User label: 11 Processing file: /content/drive/My Drive/Data/iOS/StepCount21.csv, User label: 12 Processing file: /content/drive/My Drive/Data/iOS/StepCount22.csv, User label: 13
<ipython-input-7-a477c39a373a>:14: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['startDate'] = pd.to_datetime(iphone_df['startDate'], format='%Y-%m-%d %H:%M:%S %z')
<ipython-input-7-a477c39a373a>:17: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['15min_interval'] = iphone_df['startDate'].dt.floor('15T')
<ipython-input-7-a477c39a373a>:20: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['date'] = iphone_df['15min_interval'].dt.date
<ipython-input-7-a477c39a373a>:21: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['time'] = iphone_df['15min_interval'].dt.time
Processing file: /content/drive/My Drive/Data/iOS/StepCount23.csv, User label: 14
<ipython-input-7-a477c39a373a>:14: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['startDate'] = pd.to_datetime(iphone_df['startDate'], format='%Y-%m-%d %H:%M:%S %z')
<ipython-input-7-a477c39a373a>:17: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['15min_interval'] = iphone_df['startDate'].dt.floor('15T')
<ipython-input-7-a477c39a373a>:20: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['date'] = iphone_df['15min_interval'].dt.date
<ipython-input-7-a477c39a373a>:21: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['time'] = iphone_df['15min_interval'].dt.time
Processing file: /content/drive/My Drive/Data/iOS/StepCount25.csv, User label: 15 Processing file: /content/drive/My Drive/Data/iOS/StepCount26.csv, User label: 16
<ipython-input-7-a477c39a373a>:14: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['startDate'] = pd.to_datetime(iphone_df['startDate'], format='%Y-%m-%d %H:%M:%S %z')
<ipython-input-7-a477c39a373a>:17: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['15min_interval'] = iphone_df['startDate'].dt.floor('15T')
<ipython-input-7-a477c39a373a>:20: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['date'] = iphone_df['15min_interval'].dt.date
<ipython-input-7-a477c39a373a>:21: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['time'] = iphone_df['15min_interval'].dt.time
Processing file: /content/drive/My Drive/Data/iOS/StepCount28.csv, User label: 17 Processing file: /content/drive/My Drive/Data/iOS/StepCount29.csv, User label: 18 Processing file: /content/drive/My Drive/Data/iOS/StepCount30.csv, User label: 19
<ipython-input-7-a477c39a373a>:14: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['startDate'] = pd.to_datetime(iphone_df['startDate'], format='%Y-%m-%d %H:%M:%S %z')
<ipython-input-7-a477c39a373a>:17: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['15min_interval'] = iphone_df['startDate'].dt.floor('15T')
<ipython-input-7-a477c39a373a>:20: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['date'] = iphone_df['15min_interval'].dt.date
<ipython-input-7-a477c39a373a>:21: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['time'] = iphone_df['15min_interval'].dt.time
Processing file: /content/drive/My Drive/Data/iOS/StepCount33.csv, User label: 20 Processing file: /content/drive/My Drive/Data/iOS/StepCount34.csv, User label: 21 Processing file: /content/drive/My Drive/Data/iOS/StepCount35.csv, User label: 22 Processing file: /content/drive/My Drive/Data/iOS/StepCount36.csv, User label: 23
<ipython-input-7-a477c39a373a>:14: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['startDate'] = pd.to_datetime(iphone_df['startDate'], format='%Y-%m-%d %H:%M:%S %z')
<ipython-input-7-a477c39a373a>:17: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['15min_interval'] = iphone_df['startDate'].dt.floor('15T')
<ipython-input-7-a477c39a373a>:20: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['date'] = iphone_df['15min_interval'].dt.date
<ipython-input-7-a477c39a373a>:21: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['time'] = iphone_df['15min_interval'].dt.time
Processing file: /content/drive/My Drive/Data/iOS/StepCount37.csv, User label: 24
<ipython-input-7-a477c39a373a>:14: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['startDate'] = pd.to_datetime(iphone_df['startDate'], format='%Y-%m-%d %H:%M:%S %z')
<ipython-input-7-a477c39a373a>:17: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['15min_interval'] = iphone_df['startDate'].dt.floor('15T')
<ipython-input-7-a477c39a373a>:20: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['date'] = iphone_df['15min_interval'].dt.date
<ipython-input-7-a477c39a373a>:21: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['time'] = iphone_df['15min_interval'].dt.time
Processing file: /content/drive/My Drive/Data/iOS/StepCount38.csv, User label: 25 Processing file: /content/drive/My Drive/Data/iOS/StepCount39.csv, User label: 26
<ipython-input-7-a477c39a373a>:14: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['startDate'] = pd.to_datetime(iphone_df['startDate'], format='%Y-%m-%d %H:%M:%S %z')
<ipython-input-7-a477c39a373a>:17: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['15min_interval'] = iphone_df['startDate'].dt.floor('15T')
<ipython-input-7-a477c39a373a>:20: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['date'] = iphone_df['15min_interval'].dt.date
<ipython-input-7-a477c39a373a>:21: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['time'] = iphone_df['15min_interval'].dt.time
Processing file: /content/drive/My Drive/Data/iOS/StepCount40.csv, User label: 27
<ipython-input-7-a477c39a373a>:14: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['startDate'] = pd.to_datetime(iphone_df['startDate'], format='%Y-%m-%d %H:%M:%S %z')
<ipython-input-7-a477c39a373a>:17: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['15min_interval'] = iphone_df['startDate'].dt.floor('15T')
<ipython-input-7-a477c39a373a>:20: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['date'] = iphone_df['15min_interval'].dt.date
<ipython-input-7-a477c39a373a>:21: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['time'] = iphone_df['15min_interval'].dt.time
Processing file: /content/drive/My Drive/Data/iOS/StepCount41.csv, User label: 28
Processing file: /content/drive/My Drive/Data/iOS/StepCount43.csv, User label: 29
Processing file: /content/drive/My Drive/Data/iOS/StepCount44.csv, User label: 30
Processing file: /content/drive/My Drive/Data/iOS/StepCount45.csv, User label: 31
date 00:00:00 00:15:00 00:30:00 00:45:00 01:00:00 01:15:00 \
0 2017-07-20 False False False False False False
1 2017-07-21 False False False False False False
2 2017-07-22 False False False True True False
3 2017-07-23 False False False False False False
4 2017-07-24 False True False False False False
... ... ... ... ... ... ... ...
36480 2020-06-09 False False True False False False
36481 2020-06-10 False False False False False False
36482 2020-06-11 False True False False False False
36483 2020-06-12 False False True False False False
36484 2020-06-13 False False True False False False
01:30:00 01:45:00 02:00:00 ... Month Year DayOfWeek_Friday \
0 False False False ... 7 2017 False
1 False False False ... 7 2017 True
2 False False False ... 7 2017 False
3 False False False ... 7 2017 False
4 True False False ... 7 2017 False
... ... ... ... ... ... ... ...
36480 False False False ... 6 2020 False
36481 False False False ... 6 2020 False
36482 False False False ... 6 2020 False
36483 False False False ... 6 2020 True
36484 False False False ... 6 2020 False
DayOfWeek_Monday DayOfWeek_Saturday DayOfWeek_Sunday \
0 False False False
1 False False False
2 False True False
3 False False True
4 True False False
... ... ... ...
36480 False False False
36481 False False False
36482 False False False
36483 False False False
36484 False True False
DayOfWeek_Thursday DayOfWeek_Tuesday DayOfWeek_Wednesday user
0 True False False 0
1 False False False 0
2 False False False 0
3 False False False 0
4 False False False 0
... ... ... ... ...
36480 False True False 31
36481 False False True 31
36482 True False False 31
36483 False False False 31
36484 False False False 31
[36485 rows x 107 columns]
In [ ]:
import pandas as pd
def process_file(file_path, user_label):
# Load the dataset
df = pd.read_csv(file_path, delimiter=';')
# Step 1: Filter for iPhone devices
iphone_df = df[df['device'].str.contains('iPhone', na=False)] # Treat NaN as False
# Step 2: Select the desired columns
result = iphone_df[['startDate', 'endDate', 'value']]
# Step 3: Convert startDate to datetime
iphone_df['startDate'] = pd.to_datetime(iphone_df['startDate'], format='%Y-%m-%d %H:%M:%S %z')
# Step 4: Round down the startDate to the nearest 1-hour interval
iphone_df['1hr_interval'] = iphone_df['startDate'].dt.floor('H')
# Step 5: Extract date and time
iphone_df['date'] = iphone_df['1hr_interval'].dt.date
iphone_df['time'] = iphone_df['1hr_interval'].dt.time
# Step 6: Group by date and time, then sum the values for 1-hour intervals
iphone_df_filtered = iphone_df[iphone_df['value'] > 25].dropna(subset=['value'])
interval_sum = iphone_df.groupby(['date', 'time'])['value'].sum().reset_index()
# Step 7: Pivot the data to get one row per day with columns for each 1-hour interval
pivot_table = interval_sum.pivot(index='date', columns='time', values='value').fillna(0)
# Step 8: Create a full range of 1-hour intervals (00:00:00 to 23:00:00)
full_time_range = pd.date_range('00:00', '23:00', freq='H').time
# Step 9: Reindex to include all possible 1-hour intervals and fill missing values with 0
pivot_table = pivot_table.reindex(columns=full_time_range, fill_value=0)
# Step 10: Rename columns to reflect 1-hour intervals
pivot_table.columns = [f'{str(col)}' for col in pivot_table.columns]
# Step 11: Reset index to have 'date' as a column instead of an index
pivot_table.reset_index(inplace=True)
# Step 12: Add day of the week, month, and year columns
pivot_table['DayOfWeek'] = pd.to_datetime(pivot_table['date']).dt.day_name()
pivot_table['Month'] = pd.to_datetime(pivot_table['date']).dt.month
pivot_table['Year'] = pd.to_datetime(pivot_table['date']).dt.year
# Step 13: One-hot encode the 'DayOfWeek' column
pivot_table = pd.concat([pivot_table, pd.get_dummies(pivot_table['DayOfWeek'], prefix='DayOfWeek')], axis=1)
# Step 14: Convert 1-hour interval values to binary (True if > 0, else False)
for col in pivot_table.columns[1:25]: # Skip the 'date' column and focus on 1-hour intervals
pivot_table[col] = pivot_table[col].apply(lambda x: True if x > 0 else False)
# Step 15: Add 'user' column with the specified user label
pivot_table['user'] = user_label
# Print which file is currently being processed
print(f"Processing file: {file_path}, User label: {user_label}")
# Step 16: Drop the 'DayOfWeek' column as it has been one-hot encoded
pivot_table.drop(columns=['DayOfWeek'], inplace=True)
return pivot_table
# List of files to skip
files_to_skip = {'StepCount06.csv','StepCount10.csv','StepCount12.csv', 'StepCount13.csv', 'StepCount15.csv', 'StepCount17.csv',
'StepCount18.csv', 'StepCount20.csv', 'StepCount24.csv', 'StepCount27.csv','StepCount31.csv','StepCount32.csv',
'StepCount42.csv', 'StepCount46.csv'}
# Generate file paths, skipping specified files
file_paths = [f'/content/drive/My Drive/Data/iOS/StepCount{i:02d}.csv' for i in range(1, 47)
if f'StepCount{i:02d}.csv' not in files_to_skip]
# Generate user labels based on file index
user_labels = list(range(len(file_paths)))
# Process each file with its corresponding user label and concatenate the results
processed_dfs = [process_file(file_path, user_label) for file_path, user_label in zip(file_paths, user_labels)]
combined_df = pd.concat(processed_dfs, ignore_index=True)
# Save the combined DataFrame to a new Excel file
updated_file_path = '/content/combined_aggregated_data_1hr_withthreshold.xlsx'
combined_df.to_excel(updated_file_path, index=False)
# Print the final DataFrame
print(combined_df)
<ipython-input-8-ae3c61a191b5>:14: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['startDate'] = pd.to_datetime(iphone_df['startDate'], format='%Y-%m-%d %H:%M:%S %z')
<ipython-input-8-ae3c61a191b5>:17: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['1hr_interval'] = iphone_df['startDate'].dt.floor('H')
<ipython-input-8-ae3c61a191b5>:20: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['date'] = iphone_df['1hr_interval'].dt.date
<ipython-input-8-ae3c61a191b5>:21: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['time'] = iphone_df['1hr_interval'].dt.time
Processing file: /content/drive/My Drive/Data/iOS/StepCount01.csv, User label: 0
<ipython-input-8-ae3c61a191b5>:14: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['startDate'] = pd.to_datetime(iphone_df['startDate'], format='%Y-%m-%d %H:%M:%S %z')
<ipython-input-8-ae3c61a191b5>:17: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['1hr_interval'] = iphone_df['startDate'].dt.floor('H')
<ipython-input-8-ae3c61a191b5>:20: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['date'] = iphone_df['1hr_interval'].dt.date
<ipython-input-8-ae3c61a191b5>:21: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['time'] = iphone_df['1hr_interval'].dt.time
Processing file: /content/drive/My Drive/Data/iOS/StepCount02.csv, User label: 1 Processing file: /content/drive/My Drive/Data/iOS/StepCount03.csv, User label: 2 Processing file: /content/drive/My Drive/Data/iOS/StepCount04.csv, User label: 3
<ipython-input-8-ae3c61a191b5>:14: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['startDate'] = pd.to_datetime(iphone_df['startDate'], format='%Y-%m-%d %H:%M:%S %z')
<ipython-input-8-ae3c61a191b5>:17: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['1hr_interval'] = iphone_df['startDate'].dt.floor('H')
<ipython-input-8-ae3c61a191b5>:20: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['date'] = iphone_df['1hr_interval'].dt.date
<ipython-input-8-ae3c61a191b5>:21: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['time'] = iphone_df['1hr_interval'].dt.time
Processing file: /content/drive/My Drive/Data/iOS/StepCount05.csv, User label: 4 Processing file: /content/drive/My Drive/Data/iOS/StepCount07.csv, User label: 5
<ipython-input-8-ae3c61a191b5>:14: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['startDate'] = pd.to_datetime(iphone_df['startDate'], format='%Y-%m-%d %H:%M:%S %z')
<ipython-input-8-ae3c61a191b5>:17: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['1hr_interval'] = iphone_df['startDate'].dt.floor('H')
<ipython-input-8-ae3c61a191b5>:20: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['date'] = iphone_df['1hr_interval'].dt.date
<ipython-input-8-ae3c61a191b5>:21: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['time'] = iphone_df['1hr_interval'].dt.time
<ipython-input-8-ae3c61a191b5>:14: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['startDate'] = pd.to_datetime(iphone_df['startDate'], format='%Y-%m-%d %H:%M:%S %z')
<ipython-input-8-ae3c61a191b5>:17: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['1hr_interval'] = iphone_df['startDate'].dt.floor('H')
<ipython-input-8-ae3c61a191b5>:20: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['date'] = iphone_df['1hr_interval'].dt.date
<ipython-input-8-ae3c61a191b5>:21: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['time'] = iphone_df['1hr_interval'].dt.time
Processing file: /content/drive/My Drive/Data/iOS/StepCount08.csv, User label: 6 Processing file: /content/drive/My Drive/Data/iOS/StepCount09.csv, User label: 7 Processing file: /content/drive/My Drive/Data/iOS/StepCount11.csv, User label: 8 Processing file: /content/drive/My Drive/Data/iOS/StepCount14.csv, User label: 9 Processing file: /content/drive/My Drive/Data/iOS/StepCount16.csv, User label: 10 Processing file: /content/drive/My Drive/Data/iOS/StepCount19.csv, User label: 11 Processing file: /content/drive/My Drive/Data/iOS/StepCount21.csv, User label: 12 Processing file: /content/drive/My Drive/Data/iOS/StepCount22.csv, User label: 13
<ipython-input-8-ae3c61a191b5>:14: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['startDate'] = pd.to_datetime(iphone_df['startDate'], format='%Y-%m-%d %H:%M:%S %z')
<ipython-input-8-ae3c61a191b5>:17: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['1hr_interval'] = iphone_df['startDate'].dt.floor('H')
<ipython-input-8-ae3c61a191b5>:20: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['date'] = iphone_df['1hr_interval'].dt.date
<ipython-input-8-ae3c61a191b5>:21: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['time'] = iphone_df['1hr_interval'].dt.time
Processing file: /content/drive/My Drive/Data/iOS/StepCount23.csv, User label: 14
<ipython-input-8-ae3c61a191b5>:14: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['startDate'] = pd.to_datetime(iphone_df['startDate'], format='%Y-%m-%d %H:%M:%S %z')
<ipython-input-8-ae3c61a191b5>:17: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['1hr_interval'] = iphone_df['startDate'].dt.floor('H')
<ipython-input-8-ae3c61a191b5>:20: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['date'] = iphone_df['1hr_interval'].dt.date
<ipython-input-8-ae3c61a191b5>:21: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['time'] = iphone_df['1hr_interval'].dt.time
Processing file: /content/drive/My Drive/Data/iOS/StepCount25.csv, User label: 15 Processing file: /content/drive/My Drive/Data/iOS/StepCount26.csv, User label: 16
<ipython-input-8-ae3c61a191b5>:14: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['startDate'] = pd.to_datetime(iphone_df['startDate'], format='%Y-%m-%d %H:%M:%S %z')
<ipython-input-8-ae3c61a191b5>:17: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['1hr_interval'] = iphone_df['startDate'].dt.floor('H')
<ipython-input-8-ae3c61a191b5>:20: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['date'] = iphone_df['1hr_interval'].dt.date
<ipython-input-8-ae3c61a191b5>:21: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['time'] = iphone_df['1hr_interval'].dt.time
Processing file: /content/drive/My Drive/Data/iOS/StepCount28.csv, User label: 17 Processing file: /content/drive/My Drive/Data/iOS/StepCount29.csv, User label: 18 Processing file: /content/drive/My Drive/Data/iOS/StepCount30.csv, User label: 19
<ipython-input-8-ae3c61a191b5>:14: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['startDate'] = pd.to_datetime(iphone_df['startDate'], format='%Y-%m-%d %H:%M:%S %z')
<ipython-input-8-ae3c61a191b5>:17: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['1hr_interval'] = iphone_df['startDate'].dt.floor('H')
<ipython-input-8-ae3c61a191b5>:20: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['date'] = iphone_df['1hr_interval'].dt.date
<ipython-input-8-ae3c61a191b5>:21: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['time'] = iphone_df['1hr_interval'].dt.time
Processing file: /content/drive/My Drive/Data/iOS/StepCount33.csv, User label: 20 Processing file: /content/drive/My Drive/Data/iOS/StepCount34.csv, User label: 21 Processing file: /content/drive/My Drive/Data/iOS/StepCount35.csv, User label: 22 Processing file: /content/drive/My Drive/Data/iOS/StepCount36.csv, User label: 23
<ipython-input-8-ae3c61a191b5>:14: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['startDate'] = pd.to_datetime(iphone_df['startDate'], format='%Y-%m-%d %H:%M:%S %z')
<ipython-input-8-ae3c61a191b5>:17: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['1hr_interval'] = iphone_df['startDate'].dt.floor('H')
<ipython-input-8-ae3c61a191b5>:20: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['date'] = iphone_df['1hr_interval'].dt.date
<ipython-input-8-ae3c61a191b5>:21: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['time'] = iphone_df['1hr_interval'].dt.time
Processing file: /content/drive/My Drive/Data/iOS/StepCount37.csv, User label: 24
<ipython-input-8-ae3c61a191b5>:14: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['startDate'] = pd.to_datetime(iphone_df['startDate'], format='%Y-%m-%d %H:%M:%S %z')
<ipython-input-8-ae3c61a191b5>:17: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['1hr_interval'] = iphone_df['startDate'].dt.floor('H')
<ipython-input-8-ae3c61a191b5>:20: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['date'] = iphone_df['1hr_interval'].dt.date
<ipython-input-8-ae3c61a191b5>:21: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['time'] = iphone_df['1hr_interval'].dt.time
Processing file: /content/drive/My Drive/Data/iOS/StepCount38.csv, User label: 25 Processing file: /content/drive/My Drive/Data/iOS/StepCount39.csv, User label: 26
<ipython-input-8-ae3c61a191b5>:14: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['startDate'] = pd.to_datetime(iphone_df['startDate'], format='%Y-%m-%d %H:%M:%S %z')
<ipython-input-8-ae3c61a191b5>:17: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['1hr_interval'] = iphone_df['startDate'].dt.floor('H')
<ipython-input-8-ae3c61a191b5>:20: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['date'] = iphone_df['1hr_interval'].dt.date
<ipython-input-8-ae3c61a191b5>:21: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['time'] = iphone_df['1hr_interval'].dt.time
Processing file: /content/drive/My Drive/Data/iOS/StepCount40.csv, User label: 27
<ipython-input-8-ae3c61a191b5>:14: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['startDate'] = pd.to_datetime(iphone_df['startDate'], format='%Y-%m-%d %H:%M:%S %z')
<ipython-input-8-ae3c61a191b5>:17: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['1hr_interval'] = iphone_df['startDate'].dt.floor('H')
<ipython-input-8-ae3c61a191b5>:20: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['date'] = iphone_df['1hr_interval'].dt.date
<ipython-input-8-ae3c61a191b5>:21: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
iphone_df['time'] = iphone_df['1hr_interval'].dt.time
Processing file: /content/drive/My Drive/Data/iOS/StepCount41.csv, User label: 28
Processing file: /content/drive/My Drive/Data/iOS/StepCount43.csv, User label: 29
Processing file: /content/drive/My Drive/Data/iOS/StepCount44.csv, User label: 30
Processing file: /content/drive/My Drive/Data/iOS/StepCount45.csv, User label: 31
date 00:00:00 01:00:00 02:00:00 03:00:00 04:00:00 05:00:00 \
0 2017-07-20 False False False False False False
1 2017-07-21 False False False False False False
2 2017-07-22 True True False False False False
3 2017-07-23 False False False False False False
4 2017-07-24 True True False False False False
... ... ... ... ... ... ... ...
36480 2020-06-09 True False False False False False
36481 2020-06-10 False False True False False False
36482 2020-06-11 True False False False False False
36483 2020-06-12 True False False False False False
36484 2020-06-13 True False False False False False
06:00:00 07:00:00 08:00:00 ... Month Year DayOfWeek_Friday \
0 False False False ... 7 2017 False
1 False True True ... 7 2017 True
2 False True True ... 7 2017 False
3 False False True ... 7 2017 False
4 False False True ... 7 2017 False
... ... ... ... ... ... ... ...
36480 False False False ... 6 2020 False
36481 False False False ... 6 2020 False
36482 True True True ... 6 2020 False
36483 False False False ... 6 2020 True
36484 False False False ... 6 2020 False
DayOfWeek_Monday DayOfWeek_Saturday DayOfWeek_Sunday \
0 False False False
1 False False False
2 False True False
3 False False True
4 True False False
... ... ... ...
36480 False False False
36481 False False False
36482 False False False
36483 False False False
36484 False True False
DayOfWeek_Thursday DayOfWeek_Tuesday DayOfWeek_Wednesday user
0 True False False 0
1 False False False 0
2 False False False 0
3 False False False 0
4 False False False 0
... ... ... ... ...
36480 False True False 31
36481 False False True 31
36482 True False False 31
36483 False False False 31
36484 False False False 31
[36485 rows x 35 columns]
In [ ]: