Skip to content

Instantly share code, notes, and snippets.

@Lakhan-Nad
Created May 8, 2020 09:34
Show Gist options
  • Save Lakhan-Nad/6584907dc3a004770259f28e7462d054 to your computer and use it in GitHub Desktop.
Save Lakhan-Nad/6584907dc3a004770259f28e7462d054 to your computer and use it in GitHub Desktop.
# Import Pandas Library
import pandas as pd
# Custom Exception Added
class AlreadyUpperCase(Exception):
def __init__(self):
super().__init__("DataFrame Provided Is Already In Upper Case")
pass
def upperCaseDF(data):
# Check if the data provided is Pandas DF
if(type(data) != pd.DataFrame):
raise ValueError("The Data Provided Is Not a Pandas DataFrame")
for j in data.itertuples(index=False, name=None):
for x in j:
# If Data Type is str then only apply Upper Case
if(type(x) == str):
if(x != x.upper()):
x = x.upper()
else:
raise AlreadyUpperCase
# Test Call
upperCaseDF(12)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment