问题:将具有两个字符分隔符的数据文件加载到 Azure SQL Db
时,我们遇到以下错误。我们可能做错了什么以及如何解决这个问题?
在 Azure Databricks 中使用 Python
笔记本,我们正在尝试将数据文件加载到 Azure SQL Db 。数据文件中的分隔符有两个字符~*
。在以下代码中,我们得到如下所示的错误:
pandas dataframe low memory not supported with the 'python' engine
代码:
import sqlalchemy as sq
import pandas as pd
data_df = pd.read_csv('/dbfs/FileStore/tables/MyDataFile.txt', sep='~*', engine='python', low_memory=False, quotechar='"', header='infer' , encoding='cp1252')
.............
.............
备注:如果我们删除 low_memory
选项,则会出现以下错误。尽管对于比该文件更大但具有单个字符分隔符的其他数据文件,我们不会收到以下错误。
ConnectException: Connection refused (Connection refused) Error while obtaining a new communication channel ConnectException error: This is often caused by an OOM error that causes the connection to the Python REPL to be closed. Check your query's memory usage.
最佳答案
来自 Pandas.read_csv()
的文档:
In addition, separators longer than 1 character and different from '\s+' will be interpreted as regular expressions and will also force the use of the Python parsing engine.
由于它被解释为正则表达式,并且 *
在正则表达式中具有特殊含义,因此您需要对其进行转义。使用sep=r'~\*'
关于Python 笔记本 - 导入带有两个字符分隔符的数据文件会导致错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71242932/