<jupyter_start><jupyter_text>WEEK 4 INDEPENDENT PROJECT - ELECTRIC CAR PROJECT-EMMANUEL NYAMWEYA ONG'ERA Importing our Libraries<jupyter_code>#Importing pandas

import pandas as pd

#Importing numpy

import numpy as np<jupyter_output><empty_output><jupyter_text>Loading our csv files *We can get the data and the dataset description for this Independent project here [http://bit.ly/autolib_dataset ] and here ([link text](https://drive.google.com/file/d/13DXF2CFWQLeYxxHFekng8HJnH_jtbfpN/view))*<jupyter_code>#We create and read our dataframe as follows

df = pd.read_csv("/content/Autolib_dataset (2).csv")

df<jupyter_output><empty_output><jupyter_text>Previewing our data<jupyter_code>#We use df to review our data

df
#We can preview the first 10 rows of our data as shown below

df.head(10)<jupyter_output><empty_output><jupyter_text>Accessing information about our data<jupyter_code>df.info()<jupyter_output><class 'pandas.core.frame.DataFrame'>
RangeIndex: 5000 entries, 0 to 4999
Data columns (total 25 columns):
 #   Column               Non-Null Count  Dtype 
---  ------               --------------  ----- 
 0   Address              5000 non-null   object
 1   Cars                 5000 non-null   int64 
 2   Bluecar counter      5000 non-null   int64 
 3   Utilib counter       5000 non-null   int64 
 4   Utilib 1.4 counter   5000 non-null   int64 
 5   Charge Slots         5000 non-null   int64 
 6   Charging Status      5000 non-null   object
 7   City                 5000 non-null   object
 8   Displayed comment    111 non-null    object
 9   ID                   5000 non-null   object
 10  Kind                 5000 non-null   object
 11  Geo point            5000 non-null   object
 12  Postal code          5000 non-null   int64 
 13  Public name          5000 non-null   object
 14  Rental status        5000 non-null   object
 15  Scheduled at         47 non-null     object
 16  Slots [...]<jupyter_text>Cleaning our data<jupyter_code>#Here we start by dropping columns that we will not in our analysis


df.drop(["Displayed comment", "Scheduled at", "month", "year", "Cars"], axis = 1, inplace = True)

#We then preview our data and confirm if changes have been effected 

df<jupyter_output><empty_output><jupyter_text>Uniformity<jupyter_code>#We rename columns and fix syntax errors

df.columns = df.columns.str.strip().str.lower().str.replace(' ', '_').str.replace('_counter', '').str.replace('1.4', '14')

df<jupyter_output><empty_output><jupyter_text>Removing Outliers<jupyter_code>#dropping outliers using interquantile method

Q1 = df.quantile(0.25)
Q3 = df.quantile(0.75)
IQR = Q3 - Q1

df_without_outliers = df[~((df < (Q1 - 1.5 * IQR)) | (df > (Q3 + 1.5 * IQR)))]

df_without_outliers.head(5)<jupyter_output><empty_output><jupyter_text>Checking for NaN<jupyter_code>#We check for Null values as follows

df_without_outliers.isnull().sum()<jupyter_output><empty_output><jupyter_text>Filling the null values<jupyter_code>#We use the .bfill to backward fill the missing values in our dataset. 

new_filled_data= df_without_outliers.fillna(method='bfill') #This will fill the NaN values in our dataset

#Preview our datset to see if this has been effected

new_filled_data.head()<jupyter_output><empty_output><jupyter_text>QUESTIONS *1.0 Identify 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>new_filled_data['bluecar_diff'] = new_filled_data.bluecar.diff()
new_filled_data['utilib_diff'] = new_filled_data.utilib.diff()
new_filled_data['utilib_14_diff'] = new_filled_data.utilib_14.diff()


paris = new_filled_data['city'] == 'Paris'
pickup = new_filled_data['bluecar_diff'] < 0

paris_p_p_hours = new_filled_data[paris & pickup].groupby('hour')['hour'].value_counts().sort_values(ascending = False).head(1)
paris_p_p_hours<jupyter_output><empty_output><jupyter_text>*2.0 What is the most popular hour for returning cars?*<jupyter_code>dropoff =new_filled_data['bluecar_diff'] > 0

new_filled_data[dropoff].groupby('hour')['hour'].value_counts().sort_values(ascending = False).head(1)<jupyter_output><empty_output><jupyter_text>*3.0 What postal code is the most popular for picking up Blue cars?*<jupyter_code>pickup = new_filled_data['bluecar_diff'] < 0

new_filled_data[pickup].groupby('postal_code')['hour'].count().sort_values(ascending = False).head(1)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1056322099072608, 'fraction_numerical': 0.03664329337254015, 'mean_word_length': 4.226950354609929, 'pattern_counts': {'":': 0, '<': 52, '<?xml version=': 0, '>': 51, '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': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '93747', 'license': 'MIT', 'n_tokens_mistral': 1650, 'n_tokens_neox': 1490, 'n_words': 385, 'path': "Moringa_Data_Science_Prep_W4_Independent_Project_2021_13_EMMANUEL_ONG'ERA_Python_Electric_Car_Project_.ipynb", 'repo_name': 'Mannu-kenya/Week-4-Independent-Project--MORINGA-school', 'size': '4421'}