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)

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


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

Read more here:

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: