我正在使用下面的代码进行api调用。
import requests
response = requests.get('https://myapi.com/api/v1/city', auth=('user', 'password'))
data = response.json()
希望将json负载保存为azuredatalakestorage gen2中的json文档,并从这里读取该文档。
data.write.json("wasbs://<file_system>@<storage-account-name>.dfs.core.windows.net/city.json")
error:attributeerror:“list”对象没有“write”属性
1条答案
按热度按时间rqmkfv5c1#
您需要转换json列表
data
通过使用df=spark.createDataFrame(data,schema)
,df=spark.read.json(data)
然后使用写入azure datalake存储df.write.json("wasbs://<file_system>@.dfs.core.windows.net/city.json")
Or
如果你不想变成json
然后使用spark.createDataFrame(data,schema).saveAsTextFile("<path>")
更新:尝试使用创建Dataframe
Row
对象。Example:
```data=[{'id': 1}]
from pyspark.sql import *
df=spark.createDataFrame([Row(**i) for i in data])
df.show()
+---+
| id|
+---+
| 1|
+---+
df.write.json("")