import csv
x=[]
y=[]
with open ('x_wind.txt','r') as csvfile:
plots= csv.reader(csvfile, delimiter=',')
for row in plots:
x.append(int(row[0]))
y.append(float(row[1]))
我已经编写了以上代码以从文件中提取数据
现在,我希望我的数据应打印为2018-06-14:1
样本数据为
2018061402,6.8750 2018061403,8.0000 2018061404,7.7500 2018061405,7.3750 2018061406,6.7500 2018061407,6.1250 2018061408,5.7500 2018061409,5.6250 2018061410,5.5000 2018061411,5.5000 2018061412,5.3750 2018061413,5.1250 2018061414,4.6250 2018061415,3.8750 2018061416,3.5000 2018061417,3.1250 2018061418,3.6250 2018061419,4.2500 2018061420,4.7500 2018061421,5.8750 2018061422,6.2500 2018061423,6.6250 2018061500,6.7500 2018061501,6.7500 2018061502,7.3750 2018061503,7.1250 2018061504,6.1250 2018061505,5.2500 2018061506,4.7500 2018061507,4.1250 2018061508,4.0000 2018061509,3.8750 2018061510,3.8750 2018061511,4.1250 2018061512,4.5000 2018061513,4.3750 2018061514,3.5000 2018061515,3.1250 2018061516,3.1250 2018061517,3.0000 2018061518,3.0000 2018061519,3.5000 2018061520,3.8750 2018061521,4.1250 2018061522,4.3750 2018061523,4.6250 2018061600,5.1250 2018061601,4.8750 2018061602,6.0000 2018061603,5.5000 2018061604,4.7500 2018061605,3.8750 2018061606,3.3750 2018061607,2.7500 2018061608,2.3750 2018061609,2.5000 2018061610,2.7500 2018061611,3.1250 2018061612,3.3750 2018061613,3.6250 2018061614,3.2500 2018061615,2.7500 2018061616,3.1250 2018061617,2.8750 2018061618,1.5000 2018061619,1.5000 2018061620,1.6250 2018061621,1.8750 2018061622,2.6250 2018061623,3.3750 2018061700,4.1250 2018061701,4.7500 2018061702,6.1250 2018061703,6.1250 2018061704,5.5000 2018061705,5.0000 2018061706,4.2500 2018061707,4.0000 2018061708,3.8750 2018061709,4.0000 2018061710,4.3750 2018061711,4.5000 2018061712,4.5000 2018061713,4.0000 2018061714,3.5000 2018061715,3.0000 2018061716,2.7500 2018061717,2.2500 2018061718,0.3750 2018061719,1.5000 2018061720,2.1250 2018061721,2.1250 2018061722,2.2500 2018061723,3.1250 2018061800,4.2500 2018061801,5.5000 2018061802,7.1250 2018061803,7.1250 2018061804,6.3750 2018061805,5.7500 2018061806,5.3750 2018061807,5.0000 2018061808,5.1250 2018061809,5.0000 2018061810,5.0000 2018061811,4.7500 2018061812,4.6250 2018061813,4.5000 2018061814,4.2500 2018061815,3.7500 2018061816,3.3750 2018061817,3.2500 2018061818,3.1250 2018061819,3.0000 2018061820,3.1250 2018061821,3.2500 2018061822,3.3750 2018061823,3.3750 2018061900,3.5000 2018061901,3.3750 2018061902,4.3750 2018061903,5.8750 2018061904,5.8750 2018061905,5.3750 2018061906,4.7500 2018061907,3.6250 2018061908,3.5000 2018061909,2.6250 2018061910,3.0000 2018061911,2.5000 2018061912,2.0000 2018061913,1.3750 2018061914,0.5000 2018061915,-0.2500 2018061916,-0.5000 2018061917,0.6250 2018061918,2.2500 2018061919,2.0000 2018061920,2.1250 2018061921,2.1250 2018061922,2.7500 2018061923,3.1250 2018062000,3.1250 2018062001,3.0000 2018062002,3.5000 2018062003,5.0000 2018062004,5.1250 2018062005,4.5000 2018062006,3.7500 2018062007,3.2500 2018062008,3.3750 2018062009,2.8750 2018062010,2.7500 2018062011,2.5000 2018062012,1.8750 2018062013,1.2500 2018062014,0.3750 2018062015,0.1250 2018062016,0.5000
答案 0 :(得分:0)
好像您有一个datetime对象列表。 您可以使用datetime模块将其转换为所需的格式。
例如:
import datetime
data = "2018061402"
print( datetime.datetime.strptime(data[:-2], "%Y%m%d").strftime("%Y-%m-%d") )
输出:
2018-06-14