Python 如何基于本地csv的where子句从pandas访问Google Bigquery数据

Python 如何基于本地csv的where子句从pandas访问Google Bigquery数据,python,pandas,google-bigquery,Python,Pandas,Google Bigquery,所以我有一个名为Frames的本地数据帧,它有一个列项。 我想从Google BigQuery销售数据集中提取信息。Sales有一个列itemnumber,我只想获取Frames.item中存在的那些值 我需要执行以下内容: frames=pd.DataFrame.from_csv(path,index_col=None) df = gbq.read_gbq('SELECT * FROM Usales.Sales where itemnumber in frames.item LIMIT 100

所以我有一个名为Frames的本地数据帧,它有一个列项。 我想从Google BigQuery销售数据集中提取信息。Sales有一个列itemnumber,我只想获取Frames.item中存在的那些值

我需要执行以下内容:

frames=pd.DataFrame.from_csv(path,index_col=None)
df = gbq.read_gbq('SELECT * FROM Usales.Sales where itemnumber in frames.item LIMIT 1000', project_id='Project')

您需要将应用GBQ部件的部分与数据帧应用部件分开

例如


你能把框架放到bigquery中吗?然后你能:从Usales中选择*。销售,其中itemnumber在从框架中选择不同的项目理论上说,是的,我可以但有访问限制,因此这是不可行的。这是可行的,但不是将字符串数组传递给BiqQuery并请求总共1000行,它一次遍历一个Frames.Item列,并为每个项传递1000行。需要调整使用连接的部分。现在的格式化,'.CuthFrime','Touth'。TelTISE产生一个数组,比如ABC,CDE,EFG,XYZ,而不是产生这样的东西:ABC,CDE,XYZYU是正确的-我编辑了我的回答,现在应该是好的。Cool,这对我来说是有效的,它在中间缺少了一个讨厌的括号。df=gbq.read_gbq'SELECT*FROM Usales.Sales where itemnumber in{}LIMIT 1000.format','.join'{0}.formatitem for frames['item']中的项。tolist,project_id='project'
def getDataForAnItem(item):
  # process item using gbq
  print(item)
  return  gbq.read_gbq('SELECT * FROM Usales.Sales where itemnumber in frames."+str(item)+" LIMIT 1000', project_id='Project')

frames=pd.DataFrame.from_csv(path,index_col=None)
resultDF = df['item'].apply(getDataForAnItem) 
frames=pd.DataFrame.from_csv(path,index_col=None)
df = gbq.read_gbq('SELECT * FROM Usales.Sales where itemnumber in ({}) LIMIT 1000'.format(', '.join('"{0}"'.format(item) for item in frames['item'].tolist())), project_id='project')