以下是获取精确匹配的查询
GET courses/_search
{
"query": {
"term" : {
"name.keyword": "Anthropology 230"
}
}
}
Run Code Online (Sandbox Code Playgroud)
我需要找到Anthropology 230
和Anthropology 250 also
如何获得精确匹配
我有 3 个桶1.commonfolder 2.jsonfolder 3.csvfolder
。
通用文件夹将同时包含 json 和 csv 文件
需要将所有 csv 文件复制到 csvfolder
需要将所有json文件复制到json文件夹
代码如下,用于从之后commonfolder
如何复制中获取所有文件
import boto3
s3 = boto3.client('s3')
def lambda_handler(event, context):
#List all the bucket names
response = s3.list_buckets()
for bucket in response['Buckets']:
print (bucket)
print(f'{bucket["Name"]}')
#Get the files of particular bucket
if bucket["Name"] == 'tests3json':
resp = s3.list_objects_v2(Bucket='commonfolder')
for obj in resp['Contents']:
files = obj['Key']
print(files)
if(filename.split('.')[1].lower()=='json'):
copyjson(bucket,filename)
#copyjson(jsonfolder,filename)
elif(filename.split('.')[1].lower()=='csv'):
copycsv(bucket, filename)
#copycsv(csvfolder,filename)
Run Code Online (Sandbox Code Playgroud)
需要创建一个新函数 copyjson,copycsv 来完成这项工作
需要根据文件扩展名从 common-bucket 复制到 csv-bucket 或 json-bucket
代码如下
from io import StringIO
text = '''Product,Count
Pen,10
Pencil,15
Book, 10'''
df = pd.read_csv(StringIO(text))
df.plot(x="Product", y="Count", kind="bar")
Run Code Online (Sandbox Code Playgroud)
如何在图表本身中添加过滤器,用户必须有权选择哪些product
必须显示在图表中,count
并且假设count > 11
只有 Pencil 必须出现。
有没有其他方法可以做到这一点?
如果一列是日期列,我们是否也可以使用日期列进行过滤
Dynamo 数据库有一个表员工主键作为 id
csvdynamo
下面是bucket中上传的data.csv
存储桶名称 = csvdynamo
id,name,co
20,AB,PC
21,CD,PC
22,EF,MC
23,GH,MC
Run Code Online (Sandbox Code Playgroud)
需要将以上csv插入dynamodb
伪代码
for emp in employees:
emp_data= emp.split(',')
print (emp_data)
try:
table.put_item(
Item = {
"emp_id": int(emp_data[0]),
"Name": emp_data[1],
"Company": emp_data[2]
}
)
except Exception as e:
pass
Run Code Online (Sandbox Code Playgroud) 代码如下
import json
from decimal import Decimal
from pprint import pprint
import boto3
def update_movie(title, year, rating=None, plot=None, actors=None, dynamodb=None):
if not dynamodb:
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('Movies')
response = table.update_item(
Key={
'year': year,
'title': title
},
UpdateExpression="set info.rating=:r, info.plot=:p, info.actors=:a",
ExpressionAttributeValues={
':r': Decimal(rating),
':p': plot,
':a': actors
},
ReturnValues="UPDATED_NEW"
)
return response
def lambda_handler(event, context):
update_response = update_movie(
"Rush", 2013, 8.3, "Car show",
["Daniel", "Chris", "Olivia"])
print("Update movie succeeded:")
pprint(update_response, sort_dicts=False)
Run Code Online (Sandbox Code Playgroud)
在 dynamodb 中更新密钥时,我收到以下错误
"errorMessage": "[<class 'decimal.Inexact'>, <class …
Run Code Online (Sandbox Code Playgroud) 将 3 个字典合并为一个。每个 id 都有一个元素 ( id
) 作为公共元素
d1 在下面
[{
"id": 1,
"title": "delectus aut autem"
},
{
"id": 2,
"title": "quis ut nam facilis et officia qui"
}]
Run Code Online (Sandbox Code Playgroud)
d2
[{
"id": 1,
"Level":"Gold"
},
{
"id": 2,
"Level":"Silver"
}]
Run Code Online (Sandbox Code Playgroud)
d3
[{
"id": 1,
"completed": false
},
{
"id": 2,
"completed": true
}]
Run Code Online (Sandbox Code Playgroud)
预计出
[
{
"id": 1,
"title": "delectus aut autem",
"Level":"Gold",
"completed": false
},
{
"id": 2,
"title": "quis ut nam facilis et officia qui",
"Level":"Silver" …
Run Code Online (Sandbox Code Playgroud) 我有字典,里面有字典列表
字典列表有另一个字典列表
我需要提取值并将其附加到列表中
我需要写一个函数。如果孩子有name
附加到父列表,以便任何字典传递函数列表将创建一个输出,如下所示
a = [{"id": "1", "Area": [{"id": "2", "name": "Clinical"},
{"id": "23", "name": "Delivery"}]},
{"id": "2", "Area": [{"id": "2", "name": "Clinical"},
{"id": "23", "name": "Delivery"}]}]
Run Code Online (Sandbox Code Playgroud)
预期输出:
[{"id": "1", "Area": ["Clinical", "Delivery"]},
{"id": "2", "Area": ["Clinical", "Delivery"]}]
Run Code Online (Sandbox Code Playgroud)
代码如下
result = []
temp = {}
for i in range(0,len(a)):
templist = []
b = a[i]['Area'][i]['name']
c = a[i]['id']
temp['id'] = c
templist.append(b)
temp['Area'] = templist
result.append(temp)
print (result)
Run Code Online (Sandbox Code Playgroud)
我的输出没有提取并放入列表?
python ×6
aws-lambda ×3
amazon-s3 ×2
dictionary ×2
dsl ×1
filtering ×1
graph ×1
matplotlib ×1
widget ×1