Python 笔记本 - 导入带有两个字符分隔符的数据文件会导致错误

标签 python pandas azure azure-sql-database

问题:将具有两个字符分隔符的数据文件加载到 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/

相关文章:

python - 在 python 服务器中的进程之间共享列表

python - Panda .loc 或 .iloc 从数据集中选择列

caching - Windows Azure 缓存服务是否支持集群?

azure 前门 - 为什么我们需要向后端池添加多个后端

powershell - 通过powershell向Azure RM AD应用程序添加权限

python - PyTorch 中的 LSTM 分类名称

python - .png 文件未正确保存 matplotlib

python - python中的错误处理问题

python - IBM Watson Studio : Convert an ibmdbpy.frame.IdaDataFrame 到 pandas.core.frame.DataFrame

python - 如何仅获取在 Pandas 中出现超过 X 次的那些值的虚拟值