如何在数据帧上使用 apply 函数来检索特定列?

问题描述

我编写了以下代码来下载数据集并在 DataFrame 上应用 EDA 函数

url = "https://query1.finance.yahoo.com/v7/finance/download/RELIANCE.BO?period1=1577110559&period2=1608732959&interval=1d&events=history&includeAdjustedClose=true"
r = requests.get(url)
open(stock+'.csv','wb').write(r.content)  
ril = pd.read_csv(r'RELIANCE.csv',date_parser='Date')
ril.head(10)

这里我想通过apply列检索Close列以练习df.apply()函数

def close(stock):
    print(stock.iloc[:,6])
ril.apply(close)

但是代码给出了 IndexingError as

IndexingError                             Traceback (most recent call last)
<ipython-input-21-9fad7d447930> in <module>()
----> 1 asp.apply(close)

7 frames
/usr/local/lib/python3.6/dist-packages/pandas/core/indexing.py in _has_valid_tuple(self,key)
    698         for i,k in enumerate(key):
    699             if i >= self.ndim:
--> 700                 raise IndexingError("Too many indexers")
    701             try:
    702                 self._validate_key(k,i)

IndexingError: Too many indexers

可以用df.apply()函数完成吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)