I'm new to Python and panda I'm doing something wrong with the series change which I can not see
I have a date column CFB_FECHAINICIO with a data frame that I format in a new column 'fecha' as DateTimeIndex:
df ['fecha'] = Pd.DatetimeIndex (df.CFB_FECHAINICIO) df.fecha.head () 0 2015-01-01 21:44:01 1 2015-01-02 22: 50: 50.867000 2 2015 -01-05 00: 26: 04.387000 3 2015 -01-07 00:10:03 4 2015-01-07 23:47:18 Name: fecha, dtype: datetime64 [ns]
It seems that my datetime64 column index Okay.
I have one more column that I want to put in my chains, df.mg
ts = pd.Series (Df.MG.dropna ()) ts .head () 20 4.60 29 4.67 33 4.41 34 4.44 35 4.56 Name: mg, dtype: float64
But when I use the 'fecha' index, in the form of TS value Nain Appear
ts = pd.Series (df.MG.dropna (), index = df.fecha.dropna ()) ts.head () 2015-01-20 22: 50 : 50.867000 Nayan 2015-01-08 23:08:30 Nine 2015-01-14 21:46:14 Nine 2015-01-14 23:28:13 Nain 2015-01-29 00:24:46 Nain name: MG , DTP: Float64
I've verified that all values Appear in the form, not only the first. Any clue what I'm doing wrong? Thanks in advance
Edit: I have found a solution, not sure it is best but this work Does. I can post it here if it can help you or any of you is in a better position.
df.set_index ('fecha', inplace = true) ts = pd.Series (df .MG.dropna ()) ts.head () fecha 2015-01-29 00:24 : 46 4.60 2015-02-10 23:24:50 4.67 2015-02-17 00:20:35 4.41 2015-02- 18 00:18:38 4.44 2015-02-18 22:58:48 4.56 Name: MG , Dtype: float64
No comments:
Post a Comment