我正在阅读两个不同的CSV,每个CSV的列都有日期值.在read_csv之后我想用to_datetime方法将数据转换为datetime.每个CSV中日期的格式略有不同,虽然在to_datetime格式参数中记录并指定了差异,但是一个转换正常,而另一个返回以下值错误.
ValueError: to assemble mappings requires at least that [year, month, day] be sp
ecified: [day,month,year] is missing
Run Code Online (Sandbox Code Playgroud)
第一个dte.head()
0 10/14/2016 10/17/2016 10/19/2016 8/9/2016 10/17/2016 7/20/2016
1 7/15/2016 7/18/2016 7/20/2016 6/7/2016 7/18/2016 4/19/2016
2 4/15/2016 4/14/2016 4/18/2016 3/15/2016 4/18/2016 1/14/2016
3 1/15/2016 1/19/2016 1/19/2016 10/19/2015 1/19/2016 10/13/2015
4 10/15/2015 10/14/2015 10/19/2015 7/23/2015 10/14/2015 7/15/2015
Run Code Online (Sandbox Code Playgroud)
此数据帧使用以下代码进行转换:
dte = pd.to_datetime(dte, infer_datetime_format=True)
Run Code Online (Sandbox Code Playgroud)
要么
dte = pd.to_datetime(dte[x], format='%m/%d/%Y')
Run Code Online (Sandbox Code Playgroud)
第二个dtd.head()
0 2004-01-02 2004-01-02 2004-01-09 2004-01-16 2004-01-23 2004-01-30
1 2004-01-05 2004-01-09 2004-01-16 2004-01-23 2004-01-30 2004-02-06
2 …Run Code Online (Sandbox Code Playgroud) 我需要从单个服务器中的单个文件夹下载许多文件,因此我正在寻找一种更快的方法。经过一番阅读后,似乎多线程或异步方法都可以工作,但我似乎无法让这两种方法都工作。
我正在使用的异步方法如下。这可行,即没有错误,但它一次只下载一个文件,因此不会提高速度。有没有办法修改它以便提高速度?
async def get_file(self):
async with aioftp.ClientSession(self.host, self.port, self.login, self.password) as client:
async for path, info in client.list(recursive=True):
if info["type"] == "file":
await client.download(path, destination=self.dest_dir,write_into=True, block_size=self.block_size)
def async_update(self):
loop = asyncio.get_event_loop()
loop.run_until_complete(self.get_file())
loop.close()
Run Code Online (Sandbox Code Playgroud)
然后我尝试在多处理中使用简单的 Pool() 函数,如下所示:
def simple_fetch(self,file)
file = open(self.dest_dir+filename, 'wb')
ftp.retrbinary('RETR ' + filename, file.write, 8192*(2^3)) #, 8192)
file.close()
def multi_fetch(self):
pool = Pool()
pool.map(self.simple_fetch,self.update_files)
pool.close()
pool.join()
Run Code Online (Sandbox Code Playgroud)
但这会失败并出现错误。我一回到服务器就会更新该错误。