1

In my dataframe named dfwiki, I have a column of elevation data(in mm) of countries from global mean sea level. I have a linear regression model which predicted the 'time since epoch', when the elevation will be 10 metres for respective countries.

expected_submerging = regr.predict(a)

here, 'a' was the elevation in mm.

type(expected_submerging)    #It is numpy.ndarray conataining epoch values

I want to attach this "expected_submerging" array back to my dataframe "dfwiki" as a column "Prediction", but in datetime format, not in epoch time in which it is now. To be clear:

expected_submerging[:10]

gives:

array([[1.74646146e+13],
       [6.56033448e+12],
       [7.41266564e+12],
       [1.84929707e+13],
       [1.03031800e+13],
       [2.13093693e+13],
       [5.51344947e+12],
       [1.66030190e+13],
       [3.05836516e+12],
       [8.43175724e+12]])

On trying dfwiki["predictions"]=(pd.to_datetime(expected_submerging,unit='s')) I get the following error:

ValueError: Buffer has wrong number of dimensions (expected 1, got 2)

On trying

ticks = expected_submerging.astype('datetime64[s]').tolist()
dfwiki["predictions"]=(pd.to_datetime(ticks,unit='s')) 

I get the following error:

TypeError: unhashable type: 'list'
desertnaut
  • 57,590
  • 26
  • 140
  • 166
Arju Aman
  • 412
  • 1
  • 5
  • 15
  • Looks like you need to flatten the array `expected_submerging` first. – FObersteiner Jul 26 '20 at 12:26
  • @MrFuppes How? I already tried using reshape(-1,1), I guess I don't know how to flatten! – Arju Aman Jul 26 '20 at 12:29
  • 1
    this will help you @ArjuAman https://stackoverflow.com/questions/13730468/from-nd-to-1d-arrays – prax Jul 26 '20 at 12:54
  • you can use `ravel()` to flatten; however are you sure about the unit (seconds)? how far in the future do you expect the dates to be? It might be necessary to use another datetime format than `pandas` datetime dtype as it can only be used up to year 2262 – FObersteiner Jul 26 '20 at 13:05
  • It's around year 2160, so it's pretty huge actually @MrFuppes – Arju Aman Jul 26 '20 at 14:17
  • Correction: It's around year 2500, so it's pretty huge actually!!! @MrFuppes – Arju Aman Jul 26 '20 at 14:39

0 Answers0