I have a dataframe with many metric columns all containing float output. I need to round them all to four digits. I want to loop through all the columns to do this.
import numpy as np
import pandas as pd
test_df = pd.DataFrame(np.random.randn(10,4), columns=['a','b','c','d'])
metrics = test_df.columns
metrics = metrics.tolist()
for x in metrics:
test_df.x = np.round(test_df.x, 4)
However, this gives me the error:
AttributeError: 'DataFrame' object has no attribute 'x'
Whats the best way to do this?