[英]Required format for month-day-year plot in matplotlib
I have a .csv file with one column containing the date using backslashes '/' to separate the month, day and year in one column. 我有一个.csv文件,其中一列包含使用反斜杠'/'的日期,以将月份,日期和年份分隔为一列。 The following three columns contain a mean financial value, an upper financial value and a lower financial value.
以下三列包含平均财务价值,较高财务价值和较低财务价值。 The data format look like the following example;
数据格式如下例所示;
3/2/14 18338.98 18734.07 17943.88
3/3/14 18280.09 18675.2 17884.99
3/4/14 18220.26 18614.53 17825.98
3/5/14 18160.29 18551.71 17768.87
How can I get python to read in the date column and recognize it as a date in the format of month, day, year for eventual plotting with matlibplot? 我如何让python在date列中读取并将其识别为月,日,年格式的日期,以便最终通过matlibplot进行绘图?
Use the datetime
module to create a datetime
object 使用
datetime
模块创建datetime
对象
>>> import datetime
>>> dt = datetime.datetime.strptime('3/5/14', '%m/%d/%y')
>>> dt
datetime.datetime(2014, 3, 5, 0, 0)
Use the strftime
method to create labels for the axis ticks
. 使用
strftime
方法为轴ticks
创建标签。
>>> dt.strftime('%d%b%Y')
'05Mar2014'
>>>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.