Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 条件参数的Pythonic解决方案_Python 3.x_Pandas - Fatal编程技术网

Python 3.x 条件参数的Pythonic解决方案

Python 3.x 条件参数的Pythonic解决方案,python-3.x,pandas,Python 3.x,Pandas,我有一个下面的函数,其中infle是func的参数。现在我想执行以下操作 如果infle=default,则do,df=pd.read\u csv(“/path/to/the/file/given/a.csv”) 否则,读取指定给内嵌的文件路径 def func(infile): if infile == default: df = pd.read_csv("/path/to/the/file/given/a.csv) else: df = pd.read_csv

我有一个下面的函数,其中infle是func的参数。现在我想执行以下操作

如果infle=default,则do,df=pd.read\u csv(“/path/to/the/file/given/a.csv”) 否则,读取指定给内嵌的文件路径

def func(infile):
  if infile == default:
      df = pd.read_csv("/path/to/the/file/given/a.csv)
  else:
      df = pd.read_csv(infile)

这种方法运行良好

Python中的默认参数如下所示:

def func(infle=“/path/to/the/file/given/a.csv”):
df=pd.read\U csv(填充)
当一个或多个参数的形式为parameter=表达式时 函数被称为具有参数的“默认参数值” 使用默认值时,可以从 调用,在这种情况下,将替换参数的默认值 参数有一个默认值,以下所有参数直到 “*”还必须具有默认值-这是一个语法限制 这不是用语法来表达的


我需要为infle参数提供一个选项。例如,如果infle='Y',则执行此操作,否则执行此操作,正如您所说的那样,您面临的问题是什么?默认值是多少?