我的 Excel 工作表有一列用百分比符号存储的百分比(例如“50%”)。如何强制pandas.read_excel读取字符串“50%”而不是将其转换为浮点数?
目前该read_excel实现将百分比解析为浮点数 0.5。此外,如果我添加一个converter = {col_with_percentage: str}参数,它会将其解析为字符串“0.5”。有没有办法读取原始百分比值(“50%”)?
我有两个 api 端点,一个从 http 请求中获取文件并使用 python api 将其上传到谷歌云存储桶,另一个再次下载它。在第一个视图中,我从 http 请求中获取文件内容类型并将其上传到存储桶,设置该元数据:
from google.cloud import storage
file_obj = request.FILES['file']
client = storage.Client.from_service_account_json(path.join(
path.realpath(path.dirname(__file__)),
'..',
'settings',
'api-key.json'
))
bucket = client.get_bucket('storage-bucket')
blob = bucket.blob(filename)
blob.upload_from_string(
file_text,
content_type=file_obj.content_type
)
Run Code Online (Sandbox Code Playgroud)
然后在另一个视图中,我下载了文件:
...
bucket = client.get_bucket('storage-bucket')
blob = bucket.blob(filename)
blob.download_to_filename(path)
Run Code Online (Sandbox Code Playgroud)
如何访问我之前设置的文件元数据 ( content_type)?由于实例化了一个新对象,它在 blob 对象上不再可用,但它仍然保存该文件。