User Profile

Collapse

Profile Sidebar

Collapse
ck25python
ck25python
Last Activity: Aug 6 '20, 07:23 AM
Joined: Jan 30 '20
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • Using dictionaries stored in another jupyter notebook

    Hi There,

    I have thousands of dictionaries saved in one jupyter notebook (controlled by IT), and i would like to utitlize some of the dicitonies in to my jupyter notebook.Is there a way i can achieve this.

    Example: IT-Jupyter notebook contains below dictionary (just a sample):
    Code:
    dict_sample={'HR':'Human Resource','FIN':'Finance','LG':'Legal'}
    I would like to utilize above dictionary in to my jupyter notebook....
    See more | Go to post

  • HI SioSio,

    Thanks for the advice and help with this.

    Kind regards,
    CK
    See more | Go to post

    Leave a comment:


  • Hi There,

    Is there any workaround to satisfy the above condition.
    See more | Go to post

    Leave a comment:


  • Hi There,

    Thanks for this,

    However, still, I am getting the following error after running the above code:

    Is there any better way to enhance the code to get the right output.

    Code:
    
    var=[]
     
    for i in df["Gender"]:
        for x in df["Dept"]:
     
            if i[2].lower() in 'm' and x[2:4].lower() in 'mk':
    ...
    See more | Go to post

    Leave a comment:


  • ck25python
    started a topic multiple conditional substring function

    multiple conditional substring function

    Hi There,

    I am new to python so please be kind to me.
    I am learning the substring function, so I am just trying different cases to get familiar.

    I have managed to get the output for a single substring function. However when I apply multiple conditions then I get the following error. Appreciate if you guys educate me on this.

    Code:
    data = {'name': ['John', 'Aaron', 'Anie', 'Nancy', 'Steve'],
    ...
    See more | Go to post

  • Hi There,
    Thanks for advice.
    Kind regards,
    Chandan
    See more | Go to post

    Leave a comment:


  • ck25python
    started a topic Replace the last letter when letter matches

    Replace the last letter when letter matches

    Hi There,

    If the last letter contains number 5 then I want to replace it with 0.

    id PA005 and XP095 contain 5 at the last I want to replace 5 to 0.
    In a similar fashion, if the second letter contains A then replace it with Z. ID Ba002, CA003 and Pa005 contains the second letter A and i want to replace it to Z

    Below is the dataframe:
    Code:
    data = {'id': ['BP001', ' Ba002', 'CA003', 'EF004', 'Pa005','EP001','EM050','XP095']}
    ...
    See more | Go to post

  • ck25python
    replied to Number and Character Formats
    Hi There,
    Thanks for this.
    See more | Go to post

    Leave a comment:


  • ck25python
    replied to Number and Character Formats
    Hi There,
    Thanks for the advice.
    I will make a note of it.
    See more | Go to post

    Leave a comment:


  • ck25python
    replied to Number and Character Formats
    Hi,
    Just to give you a heads up.
    This is the format I have created in SAS. and the format name is Broad Funds, I can use this format Broad Funds anytime I want in my SAS coding. Its just one-time formatting and calling that format whenever I required in my coding.
    Code:
    Value $Broad_Funds
    'DOMCSP','DOMRTS','DOMRTP'= " Domestic C'wealth Sup"
    'DOMFEE'="Domestic Fee-Paying"
    'INTON','INTRTP' ="
    ...
    See more | Go to post

    Leave a comment:


  • ck25python
    replied to Number and Character Formats
    Hi There,
    Sorry for the confusion.

    I don't want to create another data frame or the condition:
    what I meant was similar to the recent post I want to use REPLACE function.
    There was a post in StackOverflow using Apply.
    https://stackoverflow.com/questions/...ting-in-python
    I am able to do it for a single observation, but when it comes to multiple observations I am not...
    See more | Go to post

    Leave a comment:


  • ck25python
    replied to Number and Character Formats
    HI There,

    Sorry, we use that term format in SAS a lot.

    I am talking something like this below
    Code:
    broad_format={"DOMCSP":"Domestic Common Wealth Supported","DOMFEE":"Domestic Fee Paying",
                 "DOMRTS":"Domestic Research Training Scheme",
               "INTOFF":"International Offshore","INTON":"International"}
    ...
    See more | Go to post

    Leave a comment:


  • ck25python
    started a topic Number and Character Formats

    Number and Character Formats

    Hi There,

    I need your advice on formatting.

    Dataset below:

    Code:
    data = {'funds': ['DOMCSP','DOMCSP','DOMFEE','DOMFEE','INTON','INTON','INTOFF','INTOFF'], 
             'risk': [1, 2, 3, 4, 5,6,7,100]}
    df = pd.DataFrame(data, columns = ['funds', 'risk',])
    df
    If funds are DOMCSP and DOMFEE then format it as Domestic if funds are INTON and INTOFF then format it as International....
    See more | Go to post

  • HI SioSio,
    Thanks for the help with the code.
    See more | Go to post

    Leave a comment:


  • Hi There,
    Thanks for the help.
    Yes, I am getting the desired output from your code.
    I want to try one more condition from your code, I let you know the status. Until such time I will keep this question as open.
    Hope this is fine with you.
    Once again thanks for your help.
    Cheers!!
    See more | Go to post

    Leave a comment:


  • using substring and if elif condition to create new column

    Hi There,
    I am new to python so please be kind to me.
    Below is the data frame and the requirement:
    Code:
    data = {'id': ['aa11bc', 'bb22cd', 'cc33ef', 'dd44gh', 'ee55ij','ff66kl','gg77mn','hh88op'], 
            'direction': ["north, south, east, west", "north, south, east, west", "north, south/, *east, \west%", "north, south, east, west",
                          "north, south, east,
    ...
    See more | Go to post

  • Creating Multiple columns based on condition in a dataframe

    Hi There,

    I am very new to python environment.
    I am trying to replicate one of the SAS code in python.
    I want to create 3 columns based on multiple conditions:

    Below are the requirements:

    if year is 2019 i want to create a column as en2019 and assign value as 1 else assign value as 0
    same goes for year 2020.

    Another condition is

    if year=comm_year (2019=2019)...
    See more | Go to post

  • Hi,

    I tried another method and it worked but its not a very efficient one.

    Code:
    heros['var1'] = heros['age'] * heros['salary']
    
    heros.loc[((heros['name'] == 'spiderman') | (heros['name'] == 'antman')) & 
              ((heros['salary'] > 1000) & (heros['salary'] < 2000)) &
              
              ((heros['city'] != 'boston') |
              (heros['city'] != 'dubai')),'var1']
    ...
    See more | Go to post

    Leave a comment:


  • Hi,

    Code:
    def fun_check(event):
        
        if name in ("spiderman","antman") and salary in range(1000,2000) and city not in ("boston","dubai"):
            return age+salary
        else:
            return age*salary
    
    heros=heros.assign(new_col=heros.apply(fun_check(event),axis=1))
    The error I am getting it from the last line of code, where I am assigning...
    See more | Go to post

    Leave a comment:


  • ck25python
    started a topic Multiple condition using if else statement

    Multiple condition using if else statement

    Hi There,

    I am trying to replicate one of the SAS functions in Python, not sure how to do it. It would be great if you guys can assist me with this.

    Below is the requirement.

    I want to perform 2 different functions here.

    Code:
    if name in ("spiderman","antman") and salary in range(1000,2000) and city not in ("boston","dubai"):
        new_column=age+salary
    ...
    See more | Go to post
    Last edited by gits; Jan 30 '20, 01:55 PM. Reason: added code tags
No activity results to display
Show More
Working...