0

I extracted the year from the Date and added it as a new column to the Dataframe. I need it to be like 2001 but it is 2001.0
Where is the .0 coming from?

This is the Output:

                      Datum  LebensverbrauchMIN  ...  Lastfaktor    Jahr
0        2001-01-01 00:00:00            0.001986  ...    0.249508  2001.0
1        2001-01-01 00:01:00            0.000839  ...    0.249847  2001.0
2        2001-01-01 00:02:00            0.000387  ...    0.250186  2001.0

# Read in Data
InnenTemp = ["LebensverbrauchMIN","HPT", "Innentemperatur", "Verlustleistung", "SolarEintrag", "Lastfaktor"]

Klima1min = pd.read_csv("Klima_keinPV11.csv", names=InnenTemp,
                 skiprows=0)
Datum = pd.read_csv("Klima_Lufttemp_GLobalstrahlung_Interpoliert_1min.csv", usecols=["Datum"],
                 skiprows=0)
Luft = pd.read_csv("Klima_Lufttemp_GLobalstrahlung_Interpoliert_1min.csv", usecols=["Lufttemperatur"],
                 skiprows=0)


frames = [Datum, Klima1min]
a = pd.concat(frames, axis=1)
a['Datum'] = pd.to_datetime(a['Datum'], format="%Y-%m-%dT%H:%M:%S")
a.set_index('Datum')

# Extract Year from Date(tried both lines)
a['Jahr'] = pd.DatetimeIndex(a['Datum']).year
#a['Jahr'] = a['Datum'].dt.year
print(a)

Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
Eric
  • 13
  • 4

1 Answers1

0

If there is a missing value in dataframe column, it considers it as a float datatype. This happens only for int, for string it remains the same.