Question Details

No question body available.

Tags

python pandas dataframe

Answers (2)

March 13, 2026 Score: 2 Rep: 840 Quality: Low Completeness: 40%

Try to avoid .loc for type conversion. Assigning directly to the column name tells Pandas to replace the entire Series/pointer rather than trying to update the values within the existing block.

Instead of: df.loc[:, 'col'] = df['col'].astype('float64')

Try to use: df['col'] = df['col'].astype('float64')

March 13, 2026 Score: 2 Rep: 86 Quality: Low Completeness: 10%

The error happens because your DataFrame columns are int64.
But normalization produces decimal numbers (float) between 0 and 1.

Pandas does not allow putting float values into an int64 column, so it raises the error.
Simple solution is to convert the DataFrame to float first.
data = pd.readexcel("filename.xlsx", header=[10,11])
data = data.astype(float)

Then normalize.
data = (data - data.min()) / (data.max() - data.min())