Using pandas to read from .csv file but it’s cutting off the decimal places?

I am trying to read in temperature data from a .csv file using pandas. Here is a sample of the file:

enter image description here

My issue is that my code is not extracting the data to 1 decimal place? This is what I have at the moment:

# Import packages
import pandas as pd

# Open  data file
data_file_name = "data_set.csv"
data_file = pd.read_csv(data_file_name, header=2).astype(int)

# Extract temperature data
target_data = data_file["Temperature"].astype(float)
print(target_data.loc[[0]])

After adding in the print statement to see if the first value is -23.5 as it should be, instead I get:

-23.0

Why isn't my code reading the data as a float with 1 d.p?



Read more here: https://stackoverflow.com/questions/68025992/using-pandas-to-read-from-csv-file-but-its-cutting-off-the-decimal-places

Content Attribution

This content was originally published by Una Davies at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: