After atype value , there is no date format












-1















When dealing with the data, it shows the date value with some problem of the format.



      Fuel  price   DATE
0 Diesel 1669 2014-11-06
1 Diesel 1549 2014-11-02
2 Diesel 1529 2014-11-03
3 Diesel 1519 2014-11-06
4 Diesel 1529 2014-11-06


So I do this:



 import numpy as np
df_diesel['DATE']= df_diesel['DATE'].values.astype(np.int64)
df_diesel['DATE'].dtype


then, It could plot successfully. But the date format 2014-11-06 disappeared, transferred to 1544054400000000000. If I did not do this, I could not merge table or plot. That is trouble.



How to merge table and plot successfully and have the date format which won't
show 1544054400000000000 again.



the code for plotting:



from matplotlib import pyplot as plt 
%matplotlib inline
plt.title("Analyse")

plt.xlabel("DATE")
plt.ylabel("price")
plt.scatter(df_diesel['DATE'], df_diesel['price'])
plt.show()









share|improve this question

























  • Can you share your dataframe ?

    – Abdur Rehman
    Jan 20 at 0:08











  • I add the dataframe now.

    – AAlex
    Jan 20 at 0:15
















-1















When dealing with the data, it shows the date value with some problem of the format.



      Fuel  price   DATE
0 Diesel 1669 2014-11-06
1 Diesel 1549 2014-11-02
2 Diesel 1529 2014-11-03
3 Diesel 1519 2014-11-06
4 Diesel 1529 2014-11-06


So I do this:



 import numpy as np
df_diesel['DATE']= df_diesel['DATE'].values.astype(np.int64)
df_diesel['DATE'].dtype


then, It could plot successfully. But the date format 2014-11-06 disappeared, transferred to 1544054400000000000. If I did not do this, I could not merge table or plot. That is trouble.



How to merge table and plot successfully and have the date format which won't
show 1544054400000000000 again.



the code for plotting:



from matplotlib import pyplot as plt 
%matplotlib inline
plt.title("Analyse")

plt.xlabel("DATE")
plt.ylabel("price")
plt.scatter(df_diesel['DATE'], df_diesel['price'])
plt.show()









share|improve this question

























  • Can you share your dataframe ?

    – Abdur Rehman
    Jan 20 at 0:08











  • I add the dataframe now.

    – AAlex
    Jan 20 at 0:15














-1












-1








-1








When dealing with the data, it shows the date value with some problem of the format.



      Fuel  price   DATE
0 Diesel 1669 2014-11-06
1 Diesel 1549 2014-11-02
2 Diesel 1529 2014-11-03
3 Diesel 1519 2014-11-06
4 Diesel 1529 2014-11-06


So I do this:



 import numpy as np
df_diesel['DATE']= df_diesel['DATE'].values.astype(np.int64)
df_diesel['DATE'].dtype


then, It could plot successfully. But the date format 2014-11-06 disappeared, transferred to 1544054400000000000. If I did not do this, I could not merge table or plot. That is trouble.



How to merge table and plot successfully and have the date format which won't
show 1544054400000000000 again.



the code for plotting:



from matplotlib import pyplot as plt 
%matplotlib inline
plt.title("Analyse")

plt.xlabel("DATE")
plt.ylabel("price")
plt.scatter(df_diesel['DATE'], df_diesel['price'])
plt.show()









share|improve this question
















When dealing with the data, it shows the date value with some problem of the format.



      Fuel  price   DATE
0 Diesel 1669 2014-11-06
1 Diesel 1549 2014-11-02
2 Diesel 1529 2014-11-03
3 Diesel 1519 2014-11-06
4 Diesel 1529 2014-11-06


So I do this:



 import numpy as np
df_diesel['DATE']= df_diesel['DATE'].values.astype(np.int64)
df_diesel['DATE'].dtype


then, It could plot successfully. But the date format 2014-11-06 disappeared, transferred to 1544054400000000000. If I did not do this, I could not merge table or plot. That is trouble.



How to merge table and plot successfully and have the date format which won't
show 1544054400000000000 again.



the code for plotting:



from matplotlib import pyplot as plt 
%matplotlib inline
plt.title("Analyse")

plt.xlabel("DATE")
plt.ylabel("price")
plt.scatter(df_diesel['DATE'], df_diesel['price'])
plt.show()






python pandas numpy matplotlib






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 20 at 1:05







AAlex

















asked Jan 20 at 0:04









AAlexAAlex

235




235













  • Can you share your dataframe ?

    – Abdur Rehman
    Jan 20 at 0:08











  • I add the dataframe now.

    – AAlex
    Jan 20 at 0:15



















  • Can you share your dataframe ?

    – Abdur Rehman
    Jan 20 at 0:08











  • I add the dataframe now.

    – AAlex
    Jan 20 at 0:15

















Can you share your dataframe ?

– Abdur Rehman
Jan 20 at 0:08





Can you share your dataframe ?

– Abdur Rehman
Jan 20 at 0:08













I add the dataframe now.

– AAlex
Jan 20 at 0:15





I add the dataframe now.

– AAlex
Jan 20 at 0:15












1 Answer
1






active

oldest

votes


















2














I am considering only date column,



Input:



    DATE         Fuel   Price
0 2014-11-06 Diesel 1669
1 2014-11-02 Diesel 1549
2 2014-11-03 Diesel 1529
3 2014-11-06 Diesel 1519
4 2014-11-06 Diesel 1529

df['DATE']= df['DATE'].values.astype(np.int64)
df


Output:



     DATE                Fuel   Price
0 1415232000000000000 Diesel 1669
1 1414886400000000000 Diesel 1549
2 1414972800000000000 Diesel 1529
3 1415232000000000000 Diesel 1519
4 1415232000000000000 Diesel 1529


Date has been converted into timestamp. To convert it back into original format, just do,



df['DATE'] = pd.to_datetime(df['DATE'], unit='ns')
df


Output:



     DATE    Fuel   Price
0 2014-11-06 Diesel 1669
1 2014-11-02 Diesel 1549
2 2014-11-03 Diesel 1529
3 2014-11-06 Diesel 1519
4 2014-11-06 Diesel 1529


Now, plot by using this,



from matplotlib import pyplot as plt 
%matplotlib inline
plt.title("Analyse")

plt.xlabel("DATE")
plt.ylabel("Price")
plt.scatter(list(df['DATE'].values), list(df['Price'].values))
plt.show()


Output:



enter image description here






share|improve this answer


























  • I tried the code, and it returned TypeError: invalid type promotion. It could not plot now.

    – AAlex
    Jan 20 at 0:43













  • In question, you said you are getting successful plot and now your problem is to get original date format back so I solved this in this way. You should do for plotting as you was doing before and to get back dates to original format, you can follow my code.

    – Abdur Rehman
    Jan 20 at 0:54













  • After plotting, it could not do your code to format the date.

    – AAlex
    Jan 20 at 0:59











  • Share your whole code I want to see where exactly the problem is.

    – Abdur Rehman
    Jan 20 at 0:59











  • After plotting the graph, the date already showed 1544054400000000000, how could change the 1544054400000000000 on the graph?

    – AAlex
    Jan 20 at 1:02











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54272441%2fafter-atype-value-there-is-no-date-format%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














I am considering only date column,



Input:



    DATE         Fuel   Price
0 2014-11-06 Diesel 1669
1 2014-11-02 Diesel 1549
2 2014-11-03 Diesel 1529
3 2014-11-06 Diesel 1519
4 2014-11-06 Diesel 1529

df['DATE']= df['DATE'].values.astype(np.int64)
df


Output:



     DATE                Fuel   Price
0 1415232000000000000 Diesel 1669
1 1414886400000000000 Diesel 1549
2 1414972800000000000 Diesel 1529
3 1415232000000000000 Diesel 1519
4 1415232000000000000 Diesel 1529


Date has been converted into timestamp. To convert it back into original format, just do,



df['DATE'] = pd.to_datetime(df['DATE'], unit='ns')
df


Output:



     DATE    Fuel   Price
0 2014-11-06 Diesel 1669
1 2014-11-02 Diesel 1549
2 2014-11-03 Diesel 1529
3 2014-11-06 Diesel 1519
4 2014-11-06 Diesel 1529


Now, plot by using this,



from matplotlib import pyplot as plt 
%matplotlib inline
plt.title("Analyse")

plt.xlabel("DATE")
plt.ylabel("Price")
plt.scatter(list(df['DATE'].values), list(df['Price'].values))
plt.show()


Output:



enter image description here






share|improve this answer


























  • I tried the code, and it returned TypeError: invalid type promotion. It could not plot now.

    – AAlex
    Jan 20 at 0:43













  • In question, you said you are getting successful plot and now your problem is to get original date format back so I solved this in this way. You should do for plotting as you was doing before and to get back dates to original format, you can follow my code.

    – Abdur Rehman
    Jan 20 at 0:54













  • After plotting, it could not do your code to format the date.

    – AAlex
    Jan 20 at 0:59











  • Share your whole code I want to see where exactly the problem is.

    – Abdur Rehman
    Jan 20 at 0:59











  • After plotting the graph, the date already showed 1544054400000000000, how could change the 1544054400000000000 on the graph?

    – AAlex
    Jan 20 at 1:02
















2














I am considering only date column,



Input:



    DATE         Fuel   Price
0 2014-11-06 Diesel 1669
1 2014-11-02 Diesel 1549
2 2014-11-03 Diesel 1529
3 2014-11-06 Diesel 1519
4 2014-11-06 Diesel 1529

df['DATE']= df['DATE'].values.astype(np.int64)
df


Output:



     DATE                Fuel   Price
0 1415232000000000000 Diesel 1669
1 1414886400000000000 Diesel 1549
2 1414972800000000000 Diesel 1529
3 1415232000000000000 Diesel 1519
4 1415232000000000000 Diesel 1529


Date has been converted into timestamp. To convert it back into original format, just do,



df['DATE'] = pd.to_datetime(df['DATE'], unit='ns')
df


Output:



     DATE    Fuel   Price
0 2014-11-06 Diesel 1669
1 2014-11-02 Diesel 1549
2 2014-11-03 Diesel 1529
3 2014-11-06 Diesel 1519
4 2014-11-06 Diesel 1529


Now, plot by using this,



from matplotlib import pyplot as plt 
%matplotlib inline
plt.title("Analyse")

plt.xlabel("DATE")
plt.ylabel("Price")
plt.scatter(list(df['DATE'].values), list(df['Price'].values))
plt.show()


Output:



enter image description here






share|improve this answer


























  • I tried the code, and it returned TypeError: invalid type promotion. It could not plot now.

    – AAlex
    Jan 20 at 0:43













  • In question, you said you are getting successful plot and now your problem is to get original date format back so I solved this in this way. You should do for plotting as you was doing before and to get back dates to original format, you can follow my code.

    – Abdur Rehman
    Jan 20 at 0:54













  • After plotting, it could not do your code to format the date.

    – AAlex
    Jan 20 at 0:59











  • Share your whole code I want to see where exactly the problem is.

    – Abdur Rehman
    Jan 20 at 0:59











  • After plotting the graph, the date already showed 1544054400000000000, how could change the 1544054400000000000 on the graph?

    – AAlex
    Jan 20 at 1:02














2












2








2







I am considering only date column,



Input:



    DATE         Fuel   Price
0 2014-11-06 Diesel 1669
1 2014-11-02 Diesel 1549
2 2014-11-03 Diesel 1529
3 2014-11-06 Diesel 1519
4 2014-11-06 Diesel 1529

df['DATE']= df['DATE'].values.astype(np.int64)
df


Output:



     DATE                Fuel   Price
0 1415232000000000000 Diesel 1669
1 1414886400000000000 Diesel 1549
2 1414972800000000000 Diesel 1529
3 1415232000000000000 Diesel 1519
4 1415232000000000000 Diesel 1529


Date has been converted into timestamp. To convert it back into original format, just do,



df['DATE'] = pd.to_datetime(df['DATE'], unit='ns')
df


Output:



     DATE    Fuel   Price
0 2014-11-06 Diesel 1669
1 2014-11-02 Diesel 1549
2 2014-11-03 Diesel 1529
3 2014-11-06 Diesel 1519
4 2014-11-06 Diesel 1529


Now, plot by using this,



from matplotlib import pyplot as plt 
%matplotlib inline
plt.title("Analyse")

plt.xlabel("DATE")
plt.ylabel("Price")
plt.scatter(list(df['DATE'].values), list(df['Price'].values))
plt.show()


Output:



enter image description here






share|improve this answer















I am considering only date column,



Input:



    DATE         Fuel   Price
0 2014-11-06 Diesel 1669
1 2014-11-02 Diesel 1549
2 2014-11-03 Diesel 1529
3 2014-11-06 Diesel 1519
4 2014-11-06 Diesel 1529

df['DATE']= df['DATE'].values.astype(np.int64)
df


Output:



     DATE                Fuel   Price
0 1415232000000000000 Diesel 1669
1 1414886400000000000 Diesel 1549
2 1414972800000000000 Diesel 1529
3 1415232000000000000 Diesel 1519
4 1415232000000000000 Diesel 1529


Date has been converted into timestamp. To convert it back into original format, just do,



df['DATE'] = pd.to_datetime(df['DATE'], unit='ns')
df


Output:



     DATE    Fuel   Price
0 2014-11-06 Diesel 1669
1 2014-11-02 Diesel 1549
2 2014-11-03 Diesel 1529
3 2014-11-06 Diesel 1519
4 2014-11-06 Diesel 1529


Now, plot by using this,



from matplotlib import pyplot as plt 
%matplotlib inline
plt.title("Analyse")

plt.xlabel("DATE")
plt.ylabel("Price")
plt.scatter(list(df['DATE'].values), list(df['Price'].values))
plt.show()


Output:



enter image description here







share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 20 at 1:26

























answered Jan 20 at 0:27









Abdur RehmanAbdur Rehman

498510




498510













  • I tried the code, and it returned TypeError: invalid type promotion. It could not plot now.

    – AAlex
    Jan 20 at 0:43













  • In question, you said you are getting successful plot and now your problem is to get original date format back so I solved this in this way. You should do for plotting as you was doing before and to get back dates to original format, you can follow my code.

    – Abdur Rehman
    Jan 20 at 0:54













  • After plotting, it could not do your code to format the date.

    – AAlex
    Jan 20 at 0:59











  • Share your whole code I want to see where exactly the problem is.

    – Abdur Rehman
    Jan 20 at 0:59











  • After plotting the graph, the date already showed 1544054400000000000, how could change the 1544054400000000000 on the graph?

    – AAlex
    Jan 20 at 1:02



















  • I tried the code, and it returned TypeError: invalid type promotion. It could not plot now.

    – AAlex
    Jan 20 at 0:43













  • In question, you said you are getting successful plot and now your problem is to get original date format back so I solved this in this way. You should do for plotting as you was doing before and to get back dates to original format, you can follow my code.

    – Abdur Rehman
    Jan 20 at 0:54













  • After plotting, it could not do your code to format the date.

    – AAlex
    Jan 20 at 0:59











  • Share your whole code I want to see where exactly the problem is.

    – Abdur Rehman
    Jan 20 at 0:59











  • After plotting the graph, the date already showed 1544054400000000000, how could change the 1544054400000000000 on the graph?

    – AAlex
    Jan 20 at 1:02

















I tried the code, and it returned TypeError: invalid type promotion. It could not plot now.

– AAlex
Jan 20 at 0:43







I tried the code, and it returned TypeError: invalid type promotion. It could not plot now.

– AAlex
Jan 20 at 0:43















In question, you said you are getting successful plot and now your problem is to get original date format back so I solved this in this way. You should do for plotting as you was doing before and to get back dates to original format, you can follow my code.

– Abdur Rehman
Jan 20 at 0:54







In question, you said you are getting successful plot and now your problem is to get original date format back so I solved this in this way. You should do for plotting as you was doing before and to get back dates to original format, you can follow my code.

– Abdur Rehman
Jan 20 at 0:54















After plotting, it could not do your code to format the date.

– AAlex
Jan 20 at 0:59





After plotting, it could not do your code to format the date.

– AAlex
Jan 20 at 0:59













Share your whole code I want to see where exactly the problem is.

– Abdur Rehman
Jan 20 at 0:59





Share your whole code I want to see where exactly the problem is.

– Abdur Rehman
Jan 20 at 0:59













After plotting the graph, the date already showed 1544054400000000000, how could change the 1544054400000000000 on the graph?

– AAlex
Jan 20 at 1:02





After plotting the graph, the date already showed 1544054400000000000, how could change the 1544054400000000000 on the graph?

– AAlex
Jan 20 at 1:02


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54272441%2fafter-atype-value-there-is-no-date-format%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Liquibase includeAll doesn't find base path

How to use setInterval in EJS file?

Petrus Granier-Deferre