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;
}
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?
python pandas datetime
marked as duplicate by Vaishali
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.
|
show 3 more comments
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?
python pandas datetime
marked as duplicate by Vaishali
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 thisdf.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
|
show 3 more comments
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?
python pandas datetime
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
python pandas datetime
asked Nov 26 '18 at 17:39
Alex_PAlex_P
437
437
marked as duplicate by Vaishali
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
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 thisdf.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
|
show 3 more comments
1
I suspect that you have length one indices as the values in your'Date'column. That is what we call... messed up! Try thisdf.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
|
show 3 more comments
1 Answer
1
active
oldest
votes
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
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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
add a comment |
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
add a comment |
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
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
edited Nov 26 '18 at 17:49
community wiki
2 revs, 2 users 88%
piRSquared
add a comment |
add a comment |
1
I suspect that you have length one indices as the values in your
'Date'column. That is what we call... messed up! Try thisdf.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