<jupyter_start><jupyter_text>O2 Lockdown Challenge<jupyter_code># my workflow
# create environment & import required libraries
# import python libraries
import pandas as pd
#import the csv file
#only import the Name, Distance and Units data from the data.csv file as a pandas dataframe
df = pd.read_csv('data2.csv')
# just use a few columns
df_ = df[['Name','Distance','Units']]
df_
# Add a 'miles' column (dataseries) to the dataframe and set each row value for 'Miles' to 0
df_.loc[:,'Miles'] = 0
df_
# Convert distance and record value in Miles column; df_.loc[rows_by_mask,col_is_Miles] = df_['Distance'] * conversion
# miles
df_.loc[(df_['Units'] == 'Miles'), 'Miles'] = df_['Distance'] * 1
# Kilometers
# 0.621 miles = 1km
df_.loc[(df_['Units'] == 'Km'), 'Miles'] = df_['Distance'] * 0.621
# steps
# 2000 steps = 1m
df_.loc[ (df_['Units'] == 'Steps'), 'Miles'] = df_['Distance'] * 0.0005
# round to 2 decimal places
df_ = df_.round(2)
df_<jupyter_output>c:\projects\o2challenge\env\lib\site-packages\pandas\core\indexing.py:1745: 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
  isetter(ilocs[0], value)<jupyter_text>Teams<jupyter_code>df_
A = ['<NAME>','<NAME>','<NAME>', '<NAME>', '<NAME>','<NAME>','<NAME>','<NAME>']
B = ['<NAME>', '<NAME>', '<NAME>', '<NAME>', '<NAME>', '<NAME>', '<NAME>', '<NAME>']
C = ['<NAME>', '<NAME>', '<NAME>', '<NAME>','<NAME>', '<NAME>', '<NAME>', '<NAME>', '<NAME>']
df_A = df_[df_['Name'].isin(A)]
df_B = df_[df_['Name'].isin(B)]
df_C = df_[df_['Name'].isin(C)]
df_.loc[:,'Team']=0
df_
df_.loc[df_['Name'].isin(A), 'Team'] = 'A'
df_.loc[df_['Name'].isin(B), 'Team'] = 'B'
df_.loc[df_['Name'].isin(C), 'Team'] = 'C'
df_
df_ = df_.set_index(['Team','Name'])
df_

df_['sum'] = df_.groupby(['Team']).transform('sum').loc[:, ('Miles')]
df_ = df_.sort_values(by=['sum','Name'], ascending=[False,False])
df_

df_agg = df_.groupby(['Team','Name','sum']).agg({'Miles':sum})
df_agg = df_agg.sort_values(by=['sum','Miles'], ascending=[False,False])
df_agg
df_agg.to_html()
df_agg.groupby('Team', sort = False).sum().sort_values(by='Miles',ascending=0)
df_agg.groupby('Team', sort = False).sum().sort_values(by='Miles',ascending=0).to_html(header = True)
Ind_agg = df_agg.groupby('Name', sort = False).sum().sort_values(by='Miles',ascending=0)
Ind_agg
Ind_agg.to_html()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.22243864433190494, 'fraction_numerical': 0.014024152707440592, 'mean_word_length': 6.642857142857143, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '387251', 'license': 'MIT', 'n_tokens_mistral': 1021, 'n_tokens_neox': 999, 'n_words': 212, 'path': 'O2 Challenge.ipynb', 'repo_name': 'mackO2/walk', 'size': '2774'}