使用pandas获取文件的动态路径 – Python

huangapple go评论52阅读模式
英文:

dynamic path of the file using pandas - Python

问题

我正在使用pandas生成CSV文件,我需要根据文件中存储的路径创建文件。

以下是我的代码:

HA_file_path = ''' select CONFIG_VALUE from CONFIGURATIONS where CONFIG_NAME = 'HA''''

我在这里遇到语法错误,不确定如何从表中获取带有单引号的值。

另外,我需要将文件名附加上当前日期时间。

英文:

I am generating a CSV file using pandas, I need to create file based on the path stored in file.

Below is my code:

HA_file_path = ''' select CONFIG_VALUE from CONFIGURATIONS where CONFIG_NAME = 'HA''''

I am getting syntax error here, not sure how to get value with single quote from table.

Also i need to attach file name with current date time.

答案1

得分: 1

import os
os.get_cwd()

返回当前目录

from datetime import datetime
datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")

返回当前时间和日期

你可以尝试将这些字符串连接到你的文件名中

英文:
import os
os.get_cwd()

returns current directory

from datetime import datetime
datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")

returns current time & date

you can try concatenating this strings into your file name

答案2

得分: 0

尝试从包含文件名的字符串变量中删除单引号和双引号。从字符串中删除引号

英文:

Try stripping out the single and double quotes from the string variable that holds the file name.strip quotes from strings

huangapple
  • 本文由 发表于 2023年7月13日 19:26:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/76678843.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定