Skip to main content
deleted 16 characters in body
Source Link
Dejene T.
  • 979
  • 8
  • 14

Try the following

def repl(df, cols):
    for col in cols:
        df[col] = df[col].apply(lambda x: x//10 if x >= 10 and x <= 100 else x)
    return df

new_df = repl(df1, ['n1', 'n2', 'n3', 'n4'])
new_df

Output:

    time    n1    n2  n3  n4
0   11:50   1.0   2   3.0 1.0  4
1   12:50   5.0   6   1.07   8.0
2   13:50   1.08   7   6.0   500.0

Try the following

def repl(df, cols):
    for col in cols:
        df[col] = df[col].apply(lambda x: x/10 if x >= 10 and x <= 100 else x)
    return df

new_df = repl(df1, ['n1', 'n2', 'n3', 'n4'])
new_df

Output:

    time    n1  n2  n3  n4
0   11:50   1.0 2   3.0 1.0
1   12:50   5.0 6   1.0 8.0
2   13:50   1.0 7   6.0 500.0

Try the following

def repl(df, cols):
    for col in cols:
        df[col] = df[col].apply(lambda x: x//10 if x >= 10 and x <= 100 else x)
    return df

new_df = repl(df1, ['n1', 'n2', 'n3', 'n4'])
new_df

Output:

   time   n1    n2  n3  n4
0   11:50   1   2   3   4
1   12:50   5   6   7   8
2   13:50   8   7   6   500
Source Link
Dejene T.
  • 979
  • 8
  • 14

Try the following

def repl(df, cols):
    for col in cols:
        df[col] = df[col].apply(lambda x: x/10 if x >= 10 and x <= 100 else x)
    return df

new_df = repl(df1, ['n1', 'n2', 'n3', 'n4'])
new_df

Output:

    time    n1  n2  n3  n4
0   11:50   1.0 2   3.0 1.0
1   12:50   5.0 6   1.0 8.0
2   13:50   1.0 7   6.0 500.0