Created
May 8, 2020 09:34
-
-
Save Lakhan-Nad/6584907dc3a004770259f28e7462d054 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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