python - 从变量传递模式名称以在 Pyspark 中创建数据框
问题描述
尝试编写一个函数来创建数据框,其中架构名称作为参数传递给函数。
def extract_file(self, file_location={}):
for (key, value) in file_location.items():
print(key, " :: ", value)
schema_name = 'schema_' + key
# read the file and create a data frame
df = self.spark.read \
.format('csv') \
.options(header='true', delimiter='|') \
.schema(schema_name) \
.load(exec('"{}"'.format(value)))
上面的代码不起作用,因为它需要不带引号的 schema 参数。如何从不带引号的存储字符串的变量中传递参数?
解决方案
推荐阅读
- dart - 如何解决一些飞镖代码的奇怪行为
- excel - 如何仅计算具有值而不是函数的行
- javascript - 如何从多维数组中提取值以形成另一个数组?
- xamarin.android - 想在“OpenWith”弹出窗口中添加我的 android pkpass 查看器应用程序
- vba - 我可以通过按钮更改同一报告中显示的列吗?
- python - 需要密码等于日期 (d/m/y)
- sql - 如何以智能方式聚合这些行?
- powershell - Invoke-ASCmd 在 PowerShell 中返回错误/警告
- salesforce - 如何在 Salesforce 调查的图像中嵌入 URL?
- javascript - Chrome 将奇怪的矩形渲染成“毛玻璃”效果