Ok, so this is confusing because of a lack of vocabulary.
Pandas series have an index and a value: so 'series[0]' contains (index,value).
How do I get the index (in my case it is a date), out of the series by indexing the series? This is really a very simple idea...it is just encrypted by the word "index." lol.
So, to rephrase,
I need the date of the first entry in my series and the last entry, when my series is indexed by date.
just to be clear, I have a series indexed by date, so when I print it out, it prints:
12-12-2008 1.2
12-13-2008 1.3
...
and calling
df.ix[0] -> 1.2
I need:
df.something[0] -> 12-12-2008
Use df. index. rename('foo', inplace=True) to set the index name. Seems this api is available since pandas 0.13.
The get_loc() function is used to find the index of any column in the Python pandas dataframe. We simply pass the column name to get_loc() function to find index.
Got it.
df.index[0]
yields the label at index 0.
You can access the elements of your index just as you would a list. So df.index[0]
will be the first element of your index and df.index[-1]
will be the last.
Incidently if a series (or dataframe) has a non-integer index, df.ix[n]
will return the n
-th row corresponding to the n
-th element of your index.
So df.ix[0]
will return the first row and df.ix[-1]
will return the last row. So an alternative way of getting the index values would be to use df.ix[0].name
and df.ix[-1].name
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With