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 | |
# Load your CSV file | |
df = pd.read_csv('your_file.csv') | |
# Assuming your category columns are named 'cat1', 'cat2', ..., 'cat7' | |
category_columns = ['cat1', 'cat2', 'cat3', 'cat4', 'cat5', 'cat6', 'cat7'] | |
# Create a new column 'category' based on the category columns | |
df['category'] = df[category_columns].idxmax(axis=1) |
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
class DisplayBinaryTree: | |
""" | |
Utility class to display a binary tree. | |
Referrence: | |
https://stackoverflow.com/a/54074933/599456 | |
""" | |
def __init__(self): |
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
************************************************************************************************************ | |
'''highlight the maximum in a Series or DataFrame''' | |
# For more on dataframe styling refer - https://www.kaggle.com/nxrprime/styling-data-frames-covid-19-vs-conferences | |
************************************************************************************************************ | |
def highlight_max(data, color='red'): | |
attr = 'background-color: {}'.format(color) | |
if data.ndim == 1: # Series from .apply(axis=0) or axis=1 | |
is_max = data == data.max() | |
return [attr if v else '' for v in is_max] |
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 glob | |
import matplotlib.pyplot as plt | |
import matplotlib.image as mpimg | |
%matplotlib inline | |
images = [] | |
for img_path in glob.glob('./Data/1/*.png'): | |
images.append(mpimg.imread(img_path)) | |
plt.figure(figsize=(20,10)) |
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
###################################################################################################### | |
Display markdown like formtted text in notebook via code | |
###################################################################################################### | |
from IPython.display import Markdown | |
'''Display markdown formatted output like bold, italic bold etc.''' | |
def formatted_text(string): | |
display(Markdown(string)) | |
###################################################################################################### |