Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.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-使用字符串数组,将其作为函数的数据帧名称的输入传递_Python_Arrays_String_Pandas_Dataframe - Fatal编程技术网

Python-使用字符串数组,将其作为函数的数据帧名称的输入传递

Python-使用字符串数组,将其作为函数的数据帧名称的输入传递,python,arrays,string,pandas,dataframe,Python,Arrays,String,Pandas,Dataframe,我是Python新手,不确定这是否是一种愚蠢的方法(因为我可能有成千上万的代码)。我试图传递一个股票代码列表,其中有一个我单独创建的数据帧列表。我想根据数组将不同的数据帧传递到函数中。有没有关于最好的执行方法的建议 def ind (in_df): in_df['CHG']= in_df['Open'] / in_df['Close'] return ; STK = ['GOOG','TSLA','AAPL'] for index in range(len(STK))

我是Python新手,不确定这是否是一种愚蠢的方法(因为我可能有成千上万的代码)。我试图传递一个股票代码列表,其中有一个我单独创建的数据帧列表。我想根据数组将不同的数据帧传递到函数中。有没有关于最好的执行方法的建议

    def ind (in_df):
    in_df['CHG']= in_df['Open'] / in_df['Close']
    return ;

STK = ['GOOG','TSLA','AAPL']

for index in range(len(STK)):
    print (STK[index])
    ind(pd.DataFrame[STK[index]])

您可以像下面这样编写循环。这样,您就不必单独调用len或单个列表元素

STK = ['GOOG','TSLA','AAPL']

for stockCode in STK:
    print (stockCode)
    ind(pd.DataFrame[stockCode])

为了扩展这个答案,花一些时间阅读友好的Python文档,了解迭代器和生成器以及它们的所有创建和使用方法,对您很有帮助。一旦你认为你已经掌握了它们,就去读大卫·比兹利的书和相关的教程,让你大吃一惊。这是2008年写的,我至少每隔一年会重读一次。非常感谢