How do I test if an object is a pandas datetime index?

piRSquared

If I use type on a DataFrame which I know has a datetime index, I get:

In [17]: type(df.index)
Out[17]: pandas.tseries.index.DatetimeIndex

but when I test it, I get:

In [18]: type(df.index) == 'pandas.tseries.index.DatetimeIndex'
Out[18]: False

I know I assumed the type of type is a string, but I really don't know what else to try, and searching has resulted in nothing.

Andy Hayden

You can use isinstance of the DatetimeIndex class:

In [11]: dates = pd.date_range('20130101', periods=6)

In [12]: dates
Out[12]: 
<class 'pandas.tseries.index.DatetimeIndex'>
[2013-01-01 00:00:00, ..., 2013-01-06 00:00:00]
Length: 6, Freq: D, Timezone: None

In [13]: isinstance(dates, pd.DatetimeIndex)
Out[13]: True

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I properly set the Datetimeindex for a Pandas datetime object in a dataframe?

From Dev

How do I get the index of each item in a groupby object in Pandas?

From Dev

How do I add milliseconds to a DateTime object?

From Dev

How Do I use the formats in DateTime::Locale with a DateTime object?

From Dev

How can I match datetime object and Pandas date object?

From Java

How do I test for an empty JavaScript object?

From Dev

How do i get Object index in an array

From Dev

How do I get the index of an object in this array?

From Dev

How do I merge two columns in a dataframe based on a datetime index?

From Dev

How do I turn a Pandas DataFrame object with 1 main column into a Pandas Series with the index column from the original DataFrame

From Dev

How do I construct a UTC `datetime` object in Python?

From Dev

How do I create a DateTime object given UTC time and date?

From Dev

How do I get the recent json object based on datetime value?

From Dev

How do I convert an object containing an Oracle Date to a DateTime?

From Dev

Given a DateTime object, how do I get DateTimeZone in Joda Time?

From Dev

How can I do an interpolating reindex in pandas using datetime indices?

From Dev

how to duplicate pandas datetime object

From Java

In Objective-C, how do I test the object type?

From Dev

How do I refer to the index of my Pandas dataframe?

From Java

How do I convert a pandas Series or index to a Numpy array?

From Java

how do I insert a column at a specific column index in pandas?

From Dev

How do i change a single index value in pandas dataframe?

From Dev

pandas how do I retrieve the index column of multiIndex

From Dev

How do I get all the rows before a specific index in Pandas?

From Dev

How do I change the date format for a Pandas Index?

From Java

How do I translate an ISO 8601 datetime string into a Python datetime object?

From Dev

Python/Pandas: How do I convert from datetime64[ns] to datetime

From Dev

How to modify Datetime index format (UTC) in Pandas?

From Dev

How to Offset Pandas Pearson Correlation with Datetime Index

Related Related

  1. 1

    How do I properly set the Datetimeindex for a Pandas datetime object in a dataframe?

  2. 2

    How do I get the index of each item in a groupby object in Pandas?

  3. 3

    How do I add milliseconds to a DateTime object?

  4. 4

    How Do I use the formats in DateTime::Locale with a DateTime object?

  5. 5

    How can I match datetime object and Pandas date object?

  6. 6

    How do I test for an empty JavaScript object?

  7. 7

    How do i get Object index in an array

  8. 8

    How do I get the index of an object in this array?

  9. 9

    How do I merge two columns in a dataframe based on a datetime index?

  10. 10

    How do I turn a Pandas DataFrame object with 1 main column into a Pandas Series with the index column from the original DataFrame

  11. 11

    How do I construct a UTC `datetime` object in Python?

  12. 12

    How do I create a DateTime object given UTC time and date?

  13. 13

    How do I get the recent json object based on datetime value?

  14. 14

    How do I convert an object containing an Oracle Date to a DateTime?

  15. 15

    Given a DateTime object, how do I get DateTimeZone in Joda Time?

  16. 16

    How can I do an interpolating reindex in pandas using datetime indices?

  17. 17

    how to duplicate pandas datetime object

  18. 18

    In Objective-C, how do I test the object type?

  19. 19

    How do I refer to the index of my Pandas dataframe?

  20. 20

    How do I convert a pandas Series or index to a Numpy array?

  21. 21

    how do I insert a column at a specific column index in pandas?

  22. 22

    How do i change a single index value in pandas dataframe?

  23. 23

    pandas how do I retrieve the index column of multiIndex

  24. 24

    How do I get all the rows before a specific index in Pandas?

  25. 25

    How do I change the date format for a Pandas Index?

  26. 26

    How do I translate an ISO 8601 datetime string into a Python datetime object?

  27. 27

    Python/Pandas: How do I convert from datetime64[ns] to datetime

  28. 28

    How to modify Datetime index format (UTC) in Pandas?

  29. 29

    How to Offset Pandas Pearson Correlation with Datetime Index

HotTag

Archive