我在使用适用于 Python 3.8 的 AWS Lambda 时遇到了一些问题。无论我尝试运行什么代码,AWS Lambda 都会不断返回相同的响应。我正在尝试使用以下代码从 DynamoDB 实例中检索信息:
import json
import boto3
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('planets')
def lambda_handler(event, context):
response = table.get_item(
Key = {
'id':'mercury'
}
)
print(response)
# TODO implement
return {
'statusCode': 200,
'body': response)
}
Run Code Online (Sandbox Code Playgroud)
我期待类似的输出'body':{'Item': {'id':'mercury', 'temp':'sizzling hot'}},甚至是错误,但我不断收到以下响应:
Response:
{
"statusCode": 200,
"body": "\"Hello from Lambda!\""
}
Run Code Online (Sandbox Code Playgroud)
我什至更改了代码,预计会出现错误,但我仍然得到相同的输出。
我有下面的示例数据框:
d = {'key': ['foo', 'foo', 'foo', 'foo', 'bar', 'bar', 'bar', 'bar', 'crow', 'crow', 'crow', 'crow'],
'count': [12, 3, 5, 5, 3, 1, 4, 1, 7, 3, 8, 2],
'text': ["hello", "i", "am", "a", "piece", "of", "text", "have", "a", "nice", "day", "friends"],
}
}
df = pd.DataFrame(data=d)
df
Run Code Online (Sandbox Code Playgroud)
输出:
key count text
0 foo 12 hello
1 foo 3 i
2 foo 5 am
3 foo 5 a
4 bar 3 piece
5 bar 1 of
6 bar 4 text …Run Code Online (Sandbox Code Playgroud) 我有一个熊猫数据框:
import pandas as pd
test = pd.DataFrame({'words':[['foo','bar none','scare','bar','foo'],
['race','bar none','scare'],
['ten','scare','crow bird']]})
Run Code Online (Sandbox Code Playgroud)
我正在尝试获取数据框列中所有列表元素的单词/短语计数。我当前的解决方案是:
allwords = []
for index, row in test.iterrows():
for word in row['words']:
allwords.append(word)
Run Code Online (Sandbox Code Playgroud)
from collections import Counter
pd.Series(Counter(allwords)).sort_values(ascending=False)
Run Code Online (Sandbox Code Playgroud)
这可行,但我想知道是否有更快的解决方案。注意:我没有使用,' '.join()因为我不希望将短语分成单独的单词。