Align the significant figures of the Numpy array in Python Note.
※ Things necessary
import numpy as np
import pandas as pd
numpy_data = np.array([0.123456, 0.654321, 0.987654321])
#Convert numpy array to Pandas DataFrame
panda_data = pd.DataFrame(numpy_data)
#Round with 3 significant digits
panda_data = panda_data.round(3)
#Revert to Numpy format if needed
numpy_data2 = np.array(panda_data.values)
print(numpy_data2) --> [0.123, 0.654, 0.988]
In Pandas DataFrame
.round(Significant figures)
By, you can specify significant figures.
Isn't there any other good way?
Recommended Posts