digital-cognition-co-in / DigitalCognition

DigitalCognition - Main repo - Core Product
2 stars 2 forks source link

Lower case to Upper case #12

Open RohitDhankar opened 4 years ago

RohitDhankar commented 4 years ago

Write a Python method to Change text written in Lower case to Upper case . If text in the Pandas DF Cell is already in Upper case - thrown an exception . Upload Python code file here .

Call / Text - Rohit on Whatssap , in case of any issues / challenges.

Lakhan-Nad commented 4 years ago

Hello Sir, Tried Solving this issue. If there is any error or improvement please suggest. Link to Gist

RohitDhankar commented 4 years ago

Dear @Lakhan-Nad - your code has been accepted - thanks

Lakhan-Nad commented 4 years ago

Thank you!

RohitDhankar commented 4 years ago

Dear @Lakhan-Nad - Attached Jupyter Notebook . This is the recommended format for such methods - am sorry should have informed you earlier or put it in the issue comments etc . Kindly follow such a process going fwd , thanks


params = {} # params DICT with Key and value args 
params['single_col'] = 1 
# 0 - Boolean = All Columns Complete DF 
# 1 - Boolean = Single Column 
params['col_index'] = 3
# col_index = Int value Col Index 
print(params)

def upperCaseDF(df,params):
    """
    df - DataFrame
    params DICT with  Key and value args as defined above
    From FrontEnd we always get Col_Index and never Col_Name
    """
    import datetime
    dt_now = datetime.datetime.now()
    minute_now = dt_now.minute
    second_now = dt_now.second

    sn_col = params['single_col']  
    col_id = params['col_index']  
    col_name = df.columns[col_id]
    #col_id_plus = def str_upper(cell_value):
    try:
        if((cell_value != '' or cell_value != None)):
            if(type(cell_value) == str):
                if(cell_value != cell_value.upper()):
                    cell_value = cell_value.upper()
                    return cell_value
                else:
                    return cell_value
            else:
                return cell_value
        else:
            return cell_value
    except Exception as e:
        print(e)
        raise e

def upperCaseDF(df,params):
    """
    df - DataFrame
    params DICT with  Key and value args as defined above
    From FrontEnd we always get Col_Index and never Col_Name
    """
    import datetime
    dt_now = datetime.datetime.now()
    minute_now = dt_now.minute
    second_now = dt_now.second

    sn_col = params['single_col']  
    col_id = params['col_index']  
    col_name = df.columns[col_id]
    newColName = col_name + "_Is_Upper_" + str(minute_now) + str(second_now)
    sn_col_data = df.iloc[:, col_id]
    try:
        #
        if sn_col == 1:
            new_col  = sn_col_data.apply(lambda x: str_upper(x)).apply(pd.Series)
            df.insert(loc=col_id + 1, column=newColName, value=new_col)
            return df
        else:
            print(df.head(3))
            return df
    except Exception as e:
        print(e)
        raise e
upperCaseDF(df,params)

Uppercase_iPython_NoteBook.zip

Lakhan-Nad commented 4 years ago

Ok Sir. Will follow this.