Forum Discussion

Ellie_1066's avatar
Ellie_1066
Copper Contributor
Mar 14, 2025
Solved

Complicated data analys

EnkelAvslutandeHeder
k2b2n2k1b1n1Ö
k3b3n3k9b9n9S
k4b4n4   V
k5b5n5   N
k6b6n6   W
k7b7n7   G
k8b8n8   R
When any of these show up in my tabel
hand 1
ponkan result 
      
b2     
 b1    
   ö  
I want a numerick value to show up under result depending on what show upp where the number will be difrent  any sugestions on how to do this?
  • How about Python:

     

    import pandas as pd
    
    # Create your data
    data = {
        'Hand': ['pon', 'kan', ''],
        'Value1': ['b2', 'b1', 'ö'],
        'Result': [0, 0, 0]
    }
    df = pd.DataFrame(data)
    
    # Define a function for assigning numeric values
    def assign_result(row):
        if row['Value1'] == 'b2':
            return 10
        elif row['Value1'] == 'b1':
            return 20
        elif row['Value1'] == 'ö':
            return 30
        else:
            return 0
    
    # Apply the function to the DataFrame
    df['Result'] = df.apply(assign_result, axis=1)
    
    print(df)
    

     

4 Replies

  • m_tarler's avatar
    m_tarler
    Bronze Contributor

    I'm not sure what you need.  The top part almost looks like chess references to me.  But it sounds like you want a simple tabular substitution.  Try using something like XLOOKUP.  If you can give a sample sheet it may be easier to help.  If you can't post it here try sharing with OneDrive or a similar cloud option.

  • How about Python:

     

    import pandas as pd
    
    # Create your data
    data = {
        'Hand': ['pon', 'kan', ''],
        'Value1': ['b2', 'b1', 'ö'],
        'Result': [0, 0, 0]
    }
    df = pd.DataFrame(data)
    
    # Define a function for assigning numeric values
    def assign_result(row):
        if row['Value1'] == 'b2':
            return 10
        elif row['Value1'] == 'b1':
            return 20
        elif row['Value1'] == 'ö':
            return 30
        else:
            return 0
    
    # Apply the function to the DataFrame
    df['Result'] = df.apply(assign_result, axis=1)
    
    print(df)
    

     

    • Ellie_1066's avatar
      Ellie_1066
      Copper Contributor

      I had hoped fore a solution whitout phyton but it is the result I wanted to achive. Glad you could understand my midnight ramble after 5 h of staring at this problem.

  • Ellie_1066's avatar
    Ellie_1066
    Copper Contributor

    My description of the problem wasent the best if clarification is nedded let me know

Resources