This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import itertools | |
def count_df(data,data_col): | |
choco_count = data[data_col].value_counts().rename_axis(data_col).reset_index(name='count') | |
choco_data_with_counts = pd.merge(left=data, right=choco_count, left_on=data_col, right_on=data_col) | |
return choco_data_with_counts | |
def number_indicator(val, title_text, row_num, col_num): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# converting the column's datatype to 'object' | |
choco_data['reference_no'] = choco_data['reference_no'].astype('object') | |
choco_data['review_date'] = choco_data['review_date'].astype('object') | |
# selecting the object(or you can say string) type columns | |
choco_data_cat = choco_data.select_dtypes(include=['object']) | |
# showing the summary statistics | |
choco_data_cat.describe() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# removing the '%' sign from the cocoa_percent column | |
choco_data['cocoa_percent'] = choco_data['cocoa_percent'].str.strip('%') | |
# converting the datatype | |
choco_data['cocoa_percent'] = choco_data['cocoa_percent'].astype('float') | |
# showing the first 5 rows | |
choco_data['cocoa_percent'].head() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# defining a dictionary for renaming the columns | |
column_names = {"ref": "reference_no", | |
"Company (Manufacturer)": "manufacturer", | |
"Company Location": "company_loc", | |
"Review Date": "review_date", | |
"Country of Bean Origin": "bean_origin", | |
"Specific Bean Origin or Bar Name": "bar_name", | |
"Cocoa Percent": "cocoa_percent", | |
"Ingredients": "ingredients", | |
"Most Memorable Characteristics": "taste", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
query = "SELECT * FROM chocolate_database" | |
choco_data = pd.read_sql(query, conn) | |
choco_data.head() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pickle | |
import psycopg2 | |
# loading the file containing credentials | |
with open("heroku_database_credentials.pickle", "rb") as cred: | |
credential = pickle.load(cred) | |
# connecting to the postgresql database with those credentials | |
conn = psycopg2.connect(database=credential['Database'], | |
host=credential['Host'], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import pandas as pd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Column | Description | |
---|---|---|
Name of the Judge | Containing the name of the Judge | |
Gender | Gender of the Judge | |
Date of Birth | The date in which the Judges were born | |
Date of Appointment | The date on which the person was elevated as a Judge of any High Court (appointment as an Additional Judge is also considered here) | |
Date of Retirement | The date on which the person demits office as a Judge of High Court or of the Supreme Court (if elevated to it) | |
If appointed Chief Justice in any High Court | Categorical column specifying if a judge is appointed as Chief Justice or not. | |
If appointed to the Supreme Court | Categorical column specifying if a judge is appointed to the Supreme Court or not. | |
Foreign Degree in Law | If the judge has a Foreign Degree in Law or not. | |
Post-Graduate in Law | If the judge has a PG Degree in Law or not. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function minus_one!(x) | |
x .= x .+ 1 | |
end | |
K = [1, 2, 3, 4, 5] | |
modify_array!(K) | |
println(K) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
list1 = [1, 2, 3, 4 ,5] | |
list2 = ["one", "two", "three", "four", "five"] | |
new_dict = Dict(zip(list1, list2)) | |
#= | |
it will return | |
Dict(5 => "five", 4 => "four", 2 => "two", 3 => "three", 1 => "one") | |
=# |