<jupyter_start><jupyter_text>Importing our Libraries<jupyter_code># Importing Pandas an Numpy Libraries

import pandas as pd

import numpy as np<jupyter_output><empty_output><jupyter_text>Reading the Dataset from our CSV file<jupyter_code># Uploading and reading dataset

carrental = pd.read_csv("Autolib_dataset.csv")
carrental<jupyter_output><empty_output><jupyter_text>Previewing Dataset<jupyter_code>carrental.head()<jupyter_output><empty_output><jupyter_text>Accessing Information about our Dataset<jupyter_code>carrental.info()
carrental.shape
carrental.columns.values.tolist()<jupyter_output><empty_output><jupyter_text>Data Cleaning  Step 1: Finding and counting missing data<jupyter_code># Counting data in the columns

carrental.count()
# Counting all null data

np.count_nonzero(carrental.isnull())<jupyter_output><empty_output><jupyter_text>a) Recoding missing valuesWe will not drop missing values because ----instead we will recoded missing values with NA because ---<jupyter_code># Replacing all missing values with NA

carrental_recoded = carrental.fillna("NA")
carrental_recoded
# Checking for missing values in recoded dataset

np.count_nonzero(carrental_recoded.isnull())
# Verifying that the shape of the dataset is unchanged

carrental_recoded.shape<jupyter_output><empty_output><jupyter_text>Step 2 : Data Validity<jupyter_code># Dropping irrelevant data

carrental_recoded.drop(["Cars" , "Charge Slots" , "Charging Status" , "Displayed comment" , "Kind", "Geo point" , "Public name" , "Scheduled at" , "Slots", "Station type" , "Status" , "Subscription status"], axis = 1, inplace = True) 
carrental_recoded

# Verifying that only 12 columns were removed

carrental_recoded.shape<jupyter_output><empty_output><jupyter_text>Step 3 : Accuracy<jupyter_code># Checking for duplicates

carrental_recoded.duplicated().sum()
carrental_recoded.duplicated()<jupyter_output><empty_output><jupyter_text>Step 4 : Uniformity<jupyter_code>carrental_recoded.columns = carrental_recoded.columns.str.strip().str.lower().str.replace(' ', '_').str.replace('(', '').str.replace(')', '')
print(carrental_recoded)
carrental_recoded
carrental_recoded.info()<jupyter_output><class 'pandas.core.frame.DataFrame'>
RangeIndex: 5000 entries, 0 to 4999
Data columns (total 13 columns):
 #   Column              Non-Null Count  Dtype 
---  ------              --------------  ----- 
 0   address             5000 non-null   object
 1   bluecar_counter     5000 non-null   int64 
 2   utilib_counter      5000 non-null   int64 
 3   utilib_1.4_counter  5000 non-null   int64 
 4   city                5000 non-null   object
 5   id                  5000 non-null   object
 6   postal_code         5000 non-null   int64 
 7   rental_status       5000 non-null   object
 8   year                5000 non-null   int64 
 9   month               5000 non-null   int64 
 10  day                 5000 non-null   int64 
 11  hour                5000 non-null   int64 
 12  minute              5000 non-null   int64 
dtypes: int64(9), object(4)
memory usage: 507.9+ KB<jupyter_text>Step 5 : Data validationKeeping data for stations that are operational only.<jupyter_code># Only keeping data for stations that are operational

carrental_cleaned = carrental_recoded[carrental_recoded.rental_status =='operational']
carrental_cleaned

carrental_cleaned.shape<jupyter_output><empty_output><jupyter_text>Step 6 : Identifying outliers<jupyter_code>import matplotlib.pyplot as plt 
% matplotlib inline 
carrental_cleaned.boxplot(column =['bluecar_counter'], grid = False) 
carrental_cleaned.boxplot(column =['hour'], grid = False) 
fig, ax = plt.subplots()
ax.scatter(carrental_cleaned['hour'], carrental_cleaned['bluecar_counter'])
ax.set_xlabel('hour')
ax.set_ylabel('bluecar_counter')
plt.show()<jupyter_output><empty_output><jupyter_text>Analysis<jupyter_code>carrental_cleaned['bluecar_counter'].describe()
carrental_cleaned['hour'].mode()
carrental_cleaned['bluecar_counter'].groupby(carrental_cleaned['hour']).count().sort_values(ascending=False)<jupyter_output><empty_output><jupyter_text>Question 1Identify the most popular hour of the day for picking up a shared electric car (Bluecar) in the city of Paris over the month of April 2018.<jupyter_code># Filtering data for the city of Paris only, then we filtered for data when the “bluecar_counter” was zero. 

# We assumed that when “bluecar_counter” is zero, it implies that there were no cars in the station. 
# So, these were the times when the maximum number of cars were rented out. 


carrental_paris_allpickedup = carrental_cleaned[(carrental_cleaned['bluecar_counter']  == 0) & (carrental_cleaned['city'] == "Paris")]
carrental_paris_allpickedup
carrental_paris_allpickedup['hour'].mean()
carrental_paris_allpickedup['hour'].mode()
carrental_paris_allpickedup['bluecar_counter'].groupby(carrental_paris_allpickedup['hour']).count().sort_values(ascending=False)<jupyter_output><empty_output><jupyter_text>Question 2What is the most popular hour for returning cars?<jupyter_code># blue car counter = 7

carrental_allreturned = carrental_cleaned[(carrental_cleaned['bluecar_counter']  == 7)]
carrental_allreturned
carrental_allreturned['hour'].mode()
carrental_allreturned['bluecar_counter'].groupby(carrental_allreturned['hour']).count().sort_values(ascending=False)<jupyter_output><empty_output><jupyter_text>Question 3What station is the most popular? Overall?At the most popular picking hour?<jupyter_code># most popular = most time stamps

carrental_cleaned['year'].groupby(carrental_cleaned['id']).count().sort_values(ascending=False)
carrental_pophour = carrental_cleaned[(carrental_cleaned['hour']  == 16)]
carrental_pophour

carrental_pophour['year'].groupby(carrental_pophour['id']).count().sort_values(ascending=False)<jupyter_output><empty_output><jupyter_text>Question 4What postal code is the most popular for picking up Blue cars? Does the most popular station belong to that postal code?Overall?At the most popular picking hour?<jupyter_code>carrental_allpickedup = carrental_cleaned[(carrental_cleaned['bluecar_counter']  == 0)]
carrental_allpickedup
carrental_allpickedup['postal_code'].mode()
carrental_allpickedup.groupby(carrental_allpickedup['postal_code'])['bluecar_counter'].count().sort_values(ascending=False)

carrental_pophour['year'].groupby(carrental_pophour['postal_code']).count().sort_values(ascending=False)<jupyter_output><empty_output><jupyter_text>Question 5Do the results change if you consider Utilib and Utilib 1.4 instead of Blue cars?<jupyter_code>carrental_paris_allpickedup_utilib = carrental_cleaned[(carrental_cleaned['utilib_counter']  == 0) & (carrental_cleaned['city'] == "Paris")]
carrental_paris_allpickedup_utilib
carrental_paris_allpickedup_utilib['hour'].mode()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10461175777221159, 'fraction_numerical': 0.01974362752320613, 'mean_word_length': 6.2366737739872065, 'pattern_counts': {'":': 0, '<': 69, '<?xml version=': 0, '>': 69, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '17', 'dir': 'jupyter-structured-clean-dedup', 'id': '362043', 'license': 'CNRI-Python', 'n_tokens_mistral': 2411, 'n_tokens_neox': 2264, 'n_words': 473, 'path': 'Moringa_Data_Science_Prep_W4_Independent_Project_2021_05_Elveena_Yessoo_Python_Notebook.ipynb', 'repo_name': 'e-yessoo-moringa/electric-car-usage', 'size': '6787'}