Skip to content

Instantly share code, notes, and snippets.

View sauravmishra1710's full-sized avatar
👨‍💻
Learning to make the Machine Learn. AI for Medicine & Healthcare.

Saurav Mishra sauravmishra1710

👨‍💻
Learning to make the Machine Learn. AI for Medicine & Healthcare.
View GitHub Profile
@sauravmishra1710
sauravmishra1710 / category_col_map.py
Created October 16, 2024 01:00
Category Column Mapping - I have a CSV with image name as a column and 7 other columns for the image category. The category column can have either 0 or 1 as value depending on what category the image belongs to. Create a new column 'category' using pandas to show what is the category of the image
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)
@sauravmishra1710
sauravmishra1710 / DisplayBinaryTree.py
Last active May 31, 2021 06:21
Visualize a Binary Tree.
class DisplayBinaryTree:
"""
Utility class to display a binary tree.
Referrence:
https://stackoverflow.com/a/54074933/599456
"""
def __init__(self):
@sauravmishra1710
sauravmishra1710 / Highlight_Max
Last active March 17, 2020 06:37
highlight the maximum in a Series or DataFrame
************************************************************************************************************
'''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]
@sauravmishra1710
sauravmishra1710 / DisplayAllImages
Created March 3, 2020 17:22
Display all images in a folder
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))
######################################################################################################
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))
######################################################################################################