How to convert object to datetime Index [duplicate]





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0
















This question already has an answer here:




  • python pandas convert index to datetime

    3 answers




I have dataframe with colum date. The values of the Date column is like Index([2011-01-10], dtype='object'). I want to convert to DateTime but I am not able to do this. I have tried df["Date"] = pd.to_datetime(df["Date"]) but it did not work. Got an error TypeError: <class 'pandas.core.indexes.base.Index'> is not convertible to datetime. Can anyone help me in solving this?










share|improve this question













marked as duplicate by Vaishali pandas
Users with the  pandas badge can single-handedly close pandas questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 26 '18 at 17:45


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • 1





    I suspect that you have length one indices as the values in your 'Date' column. That is what we call... messed up! Try this df.Date = pd.to_datetime(df.Date.str[0])

    – piRSquared
    Nov 26 '18 at 17:42











  • Try to pass the date index to a column using df['dateindex'] = df.index and then convert to datetime. Or even better as @Vaishali mention, directly convert using df.index.

    – Guillaume Legoy
    Nov 26 '18 at 17:42













  • Wait, this is strange. The COLUMN date is an Index?

    – Daniel Severo
    Nov 26 '18 at 17:42











  • Since date is an index, use df.index = pd.to_datetime(df.index)

    – Vaishali
    Nov 26 '18 at 17:42











  • OP, if the dup target satisfies your needs, please say so. Otherwise, I can reopen the question.

    – piRSquared
    Nov 26 '18 at 17:46


















0
















This question already has an answer here:




  • python pandas convert index to datetime

    3 answers




I have dataframe with colum date. The values of the Date column is like Index([2011-01-10], dtype='object'). I want to convert to DateTime but I am not able to do this. I have tried df["Date"] = pd.to_datetime(df["Date"]) but it did not work. Got an error TypeError: <class 'pandas.core.indexes.base.Index'> is not convertible to datetime. Can anyone help me in solving this?










share|improve this question













marked as duplicate by Vaishali pandas
Users with the  pandas badge can single-handedly close pandas questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 26 '18 at 17:45


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • 1





    I suspect that you have length one indices as the values in your 'Date' column. That is what we call... messed up! Try this df.Date = pd.to_datetime(df.Date.str[0])

    – piRSquared
    Nov 26 '18 at 17:42











  • Try to pass the date index to a column using df['dateindex'] = df.index and then convert to datetime. Or even better as @Vaishali mention, directly convert using df.index.

    – Guillaume Legoy
    Nov 26 '18 at 17:42













  • Wait, this is strange. The COLUMN date is an Index?

    – Daniel Severo
    Nov 26 '18 at 17:42











  • Since date is an index, use df.index = pd.to_datetime(df.index)

    – Vaishali
    Nov 26 '18 at 17:42











  • OP, if the dup target satisfies your needs, please say so. Otherwise, I can reopen the question.

    – piRSquared
    Nov 26 '18 at 17:46














0












0








0









This question already has an answer here:




  • python pandas convert index to datetime

    3 answers




I have dataframe with colum date. The values of the Date column is like Index([2011-01-10], dtype='object'). I want to convert to DateTime but I am not able to do this. I have tried df["Date"] = pd.to_datetime(df["Date"]) but it did not work. Got an error TypeError: <class 'pandas.core.indexes.base.Index'> is not convertible to datetime. Can anyone help me in solving this?










share|improve this question















This question already has an answer here:




  • python pandas convert index to datetime

    3 answers




I have dataframe with colum date. The values of the Date column is like Index([2011-01-10], dtype='object'). I want to convert to DateTime but I am not able to do this. I have tried df["Date"] = pd.to_datetime(df["Date"]) but it did not work. Got an error TypeError: <class 'pandas.core.indexes.base.Index'> is not convertible to datetime. Can anyone help me in solving this?





This question already has an answer here:




  • python pandas convert index to datetime

    3 answers








python pandas datetime






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 26 '18 at 17:39









Alex_PAlex_P

437




437




marked as duplicate by Vaishali pandas
Users with the  pandas badge can single-handedly close pandas questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 26 '18 at 17:45


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by Vaishali pandas
Users with the  pandas badge can single-handedly close pandas questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 26 '18 at 17:45


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.










  • 1





    I suspect that you have length one indices as the values in your 'Date' column. That is what we call... messed up! Try this df.Date = pd.to_datetime(df.Date.str[0])

    – piRSquared
    Nov 26 '18 at 17:42











  • Try to pass the date index to a column using df['dateindex'] = df.index and then convert to datetime. Or even better as @Vaishali mention, directly convert using df.index.

    – Guillaume Legoy
    Nov 26 '18 at 17:42













  • Wait, this is strange. The COLUMN date is an Index?

    – Daniel Severo
    Nov 26 '18 at 17:42











  • Since date is an index, use df.index = pd.to_datetime(df.index)

    – Vaishali
    Nov 26 '18 at 17:42











  • OP, if the dup target satisfies your needs, please say so. Otherwise, I can reopen the question.

    – piRSquared
    Nov 26 '18 at 17:46














  • 1





    I suspect that you have length one indices as the values in your 'Date' column. That is what we call... messed up! Try this df.Date = pd.to_datetime(df.Date.str[0])

    – piRSquared
    Nov 26 '18 at 17:42











  • Try to pass the date index to a column using df['dateindex'] = df.index and then convert to datetime. Or even better as @Vaishali mention, directly convert using df.index.

    – Guillaume Legoy
    Nov 26 '18 at 17:42













  • Wait, this is strange. The COLUMN date is an Index?

    – Daniel Severo
    Nov 26 '18 at 17:42











  • Since date is an index, use df.index = pd.to_datetime(df.index)

    – Vaishali
    Nov 26 '18 at 17:42











  • OP, if the dup target satisfies your needs, please say so. Otherwise, I can reopen the question.

    – piRSquared
    Nov 26 '18 at 17:46








1




1





I suspect that you have length one indices as the values in your 'Date' column. That is what we call... messed up! Try this df.Date = pd.to_datetime(df.Date.str[0])

– piRSquared
Nov 26 '18 at 17:42





I suspect that you have length one indices as the values in your 'Date' column. That is what we call... messed up! Try this df.Date = pd.to_datetime(df.Date.str[0])

– piRSquared
Nov 26 '18 at 17:42













Try to pass the date index to a column using df['dateindex'] = df.index and then convert to datetime. Or even better as @Vaishali mention, directly convert using df.index.

– Guillaume Legoy
Nov 26 '18 at 17:42







Try to pass the date index to a column using df['dateindex'] = df.index and then convert to datetime. Or even better as @Vaishali mention, directly convert using df.index.

– Guillaume Legoy
Nov 26 '18 at 17:42















Wait, this is strange. The COLUMN date is an Index?

– Daniel Severo
Nov 26 '18 at 17:42





Wait, this is strange. The COLUMN date is an Index?

– Daniel Severo
Nov 26 '18 at 17:42













Since date is an index, use df.index = pd.to_datetime(df.index)

– Vaishali
Nov 26 '18 at 17:42





Since date is an index, use df.index = pd.to_datetime(df.index)

– Vaishali
Nov 26 '18 at 17:42













OP, if the dup target satisfies your needs, please say so. Otherwise, I can reopen the question.

– piRSquared
Nov 26 '18 at 17:46





OP, if the dup target satisfies your needs, please say so. Otherwise, I can reopen the question.

– piRSquared
Nov 26 '18 at 17:46












1 Answer
1






active

oldest

votes


















2














Setup



df = pd.DataFrame(dict(Date=[pd.Index(['2018-01-01'])] * 2))

df

Date
0 Index(['2018-01-01'], dtype='object')
1 Index(['2018-01-01'], dtype='object')




The Error



df.Date = pd.to_datetime(df.Date)    

TypeError: <class 'pandas.core.indexes.base.Index'> is not convertible to datetime




Solution



df.Date = pd.to_datetime(df.Date.str[0])

df

Date
0 2018-01-01
1 2018-01-01





share|improve this answer
































    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    Setup



    df = pd.DataFrame(dict(Date=[pd.Index(['2018-01-01'])] * 2))

    df

    Date
    0 Index(['2018-01-01'], dtype='object')
    1 Index(['2018-01-01'], dtype='object')




    The Error



    df.Date = pd.to_datetime(df.Date)    

    TypeError: <class 'pandas.core.indexes.base.Index'> is not convertible to datetime




    Solution



    df.Date = pd.to_datetime(df.Date.str[0])

    df

    Date
    0 2018-01-01
    1 2018-01-01





    share|improve this answer






























      2














      Setup



      df = pd.DataFrame(dict(Date=[pd.Index(['2018-01-01'])] * 2))

      df

      Date
      0 Index(['2018-01-01'], dtype='object')
      1 Index(['2018-01-01'], dtype='object')




      The Error



      df.Date = pd.to_datetime(df.Date)    

      TypeError: <class 'pandas.core.indexes.base.Index'> is not convertible to datetime




      Solution



      df.Date = pd.to_datetime(df.Date.str[0])

      df

      Date
      0 2018-01-01
      1 2018-01-01





      share|improve this answer




























        2












        2








        2







        Setup



        df = pd.DataFrame(dict(Date=[pd.Index(['2018-01-01'])] * 2))

        df

        Date
        0 Index(['2018-01-01'], dtype='object')
        1 Index(['2018-01-01'], dtype='object')




        The Error



        df.Date = pd.to_datetime(df.Date)    

        TypeError: <class 'pandas.core.indexes.base.Index'> is not convertible to datetime




        Solution



        df.Date = pd.to_datetime(df.Date.str[0])

        df

        Date
        0 2018-01-01
        1 2018-01-01





        share|improve this answer















        Setup



        df = pd.DataFrame(dict(Date=[pd.Index(['2018-01-01'])] * 2))

        df

        Date
        0 Index(['2018-01-01'], dtype='object')
        1 Index(['2018-01-01'], dtype='object')




        The Error



        df.Date = pd.to_datetime(df.Date)    

        TypeError: <class 'pandas.core.indexes.base.Index'> is not convertible to datetime




        Solution



        df.Date = pd.to_datetime(df.Date.str[0])

        df

        Date
        0 2018-01-01
        1 2018-01-01






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 26 '18 at 17:49


























        community wiki





        2 revs, 2 users 88%
        piRSquared


















            Popular posts from this blog

            Tonle Sap (See)

            I get strange results when I access the Sqlitedatabase with Unity C# via XAMPP

            Guatemaltekische Davis-Cup-Mannschaft