Answers for "round all data in dataframe"

C++
1

round all columns in R dataframe to 3 digits

round_df <- function(x, digits) {
    # round all numeric variables
    # x: data frame 
    # digits: number of digits to round
    numeric_columns <- sapply(x, mode) == 'numeric'
    x[numeric_columns] <-  round(x[numeric_columns], digits)
    x
}

round_df(data, 3)
Posted by: Guest on November-18-2020
0

rounding values in pandas dataframe

df['DataFrame column'].round(decimals = number of decimal places needed)
Posted by: Guest on January-08-2022

Code answers related to "round all data in dataframe"

Browse Popular Code Answers by Language