当我尝试从 excel 文件发送多列以运行时,如何修复太多值无法在 python 中解压?
How to fix too many values to unpack in python when i am trying to send multiple columns from an excel file to function?
我正在尝试将从 excel 文件读取的列中的两列发送到 google 自定义搜索函数。我在循环中遇到错误:
导入 os
打印(os.getcwd())
import pandas
df = pandas.read_excel('contactibility_sample.xlsx')
#print the column names
from googleapiclient.discovery import build
my_api_key = ""
my_cse_id = ""
def google_search(search_term, orTerms, api_key, cse_id, **kwargs):
service = build("customsearch", "v1", developerKey=api_key)
res = service.cse().list(q=search_term, orTerms=college, cx=cse_id, **kwargs).execute()
return res['items']
values = df['Contact_name'].values
college_name = df['College_name'].values
for name,college in values,college_name:
results = google_search(name, college, my_api_key, my_cse_id, num=5)
for result in results:
print result[u'formattedUrl']
错误
runfile('C:/Users/abc/untitled14.py', wdir='C:/Users/abc')
C:\Users\abc
Traceback (most recent call last):
File "<ipython-input-37-8f88ce8c799d>", line 1, in <module>
runfile('C:/Users/abc/untitled14.py', wdir='C:/Users/abc')
File "C:\Users\abc\Anaconda2\lib\site-packages\spyder\utils\site\sitecustomize.py", line 880, in runfile
execfile(filename, namespace)
File "C:\Users\abc\Anaconda2\lib\site-packages\spyder\utils\site\sitecustomize.py", line 87, in execfile
exec(compile(scripttext, filename, 'exec'), glob, loc)
File "C:/Users/abc/untitled14.py", line 33, in <module>
for name,college in values,college_name:
ValueError: too many values to unpack
我的 excel 文件是:
Contact_name Mobile_number College_name loan_id Age
Subham Biswas 9169999996 R.A.I.T 87867 23
Ketaki Joshi 9898989821 IBS 65432 24
Prashant Roy 9090909090 VIT 22342 28
Roshni singh 9191919191 IBS 23331 24
您可能希望 zip
一起 values
和 college_name
在遍历它们之前。
for name,college in zip(values, college_name):
...
我正在尝试将从 excel 文件读取的列中的两列发送到 google 自定义搜索函数。我在循环中遇到错误: 导入 os 打印(os.getcwd())
import pandas
df = pandas.read_excel('contactibility_sample.xlsx')
#print the column names
from googleapiclient.discovery import build
my_api_key = ""
my_cse_id = ""
def google_search(search_term, orTerms, api_key, cse_id, **kwargs):
service = build("customsearch", "v1", developerKey=api_key)
res = service.cse().list(q=search_term, orTerms=college, cx=cse_id, **kwargs).execute()
return res['items']
values = df['Contact_name'].values
college_name = df['College_name'].values
for name,college in values,college_name:
results = google_search(name, college, my_api_key, my_cse_id, num=5)
for result in results:
print result[u'formattedUrl']
错误
runfile('C:/Users/abc/untitled14.py', wdir='C:/Users/abc')
C:\Users\abc
Traceback (most recent call last):
File "<ipython-input-37-8f88ce8c799d>", line 1, in <module>
runfile('C:/Users/abc/untitled14.py', wdir='C:/Users/abc')
File "C:\Users\abc\Anaconda2\lib\site-packages\spyder\utils\site\sitecustomize.py", line 880, in runfile
execfile(filename, namespace)
File "C:\Users\abc\Anaconda2\lib\site-packages\spyder\utils\site\sitecustomize.py", line 87, in execfile
exec(compile(scripttext, filename, 'exec'), glob, loc)
File "C:/Users/abc/untitled14.py", line 33, in <module>
for name,college in values,college_name:
ValueError: too many values to unpack
我的 excel 文件是:
Contact_name Mobile_number College_name loan_id Age
Subham Biswas 9169999996 R.A.I.T 87867 23
Ketaki Joshi 9898989821 IBS 65432 24
Prashant Roy 9090909090 VIT 22342 28
Roshni singh 9191919191 IBS 23331 24
您可能希望 zip
一起 values
和 college_name
在遍历它们之前。
for name,college in zip(values, college_name):
...