我有一个Numpy数组,我想保存(130,000 x 3)我想使用Pickle保存,使用以下代码.但是,我一直在pkl.load行中收到错误"EOFError:Ran out of input"或"UnsupportedOperation:read".这是我第一次使用Pickle,任何想法?
谢谢,
一只蚂蚁
import pickle as pkl
import numpy as np
arrayInput = np.zeros((1000,2)) #Trial input
save = True
load = True
filename = path + 'CNN_Input'
fileObject = open(fileName, 'wb')
if save:
pkl.dump(arrayInput, fileObject)
fileObject.close()
if load:
fileObject2 = open(fileName, 'wb')
modelInput = pkl.load(fileObject2)
fileObject2.close()
if arrayInput == modelInput:
Print(True)
Run Code Online (Sandbox Code Playgroud) 我的数据集具有欧洲格式的日期,在将其传递给 pd.to_datetime 之前,我正在努力将其转换为正确的格式,因此对于所有 < 12 日,我的月份和日期切换。有一个简单的解决方案吗?
import pandas as pd
import datetime as dt
df = pd.read_csv(loc,dayfirst=True)
df['Date']=pd.to_datetime(df['Date'])
Run Code Online (Sandbox Code Playgroud)
有没有办法强制日期时间确认输入的格式为 dd/mm/yy?
谢谢您的帮助!
编辑,我的日期的样本:
renewal["Date"].head()
Out[235]:
0 31/03/2018
2 30/04/2018
3 28/02/2018
4 30/04/2018
5 31/03/2018
Name: Earliest renewal date, dtype: object
Run Code Online (Sandbox Code Playgroud)
运行以下命令后:
renewal['Date']=pd.to_datetime(renewal['Date'],dayfirst=True)
Run Code Online (Sandbox Code Playgroud)
我得到:
Out[241]:
0 2018-03-31 #Correct
2 2018-04-01 #<-- this number is wrong and should be 01-04 instad
3 2018-02-28 #Correct
Run Code Online (Sandbox Code Playgroud)