Код: Выделить всё
pandasВот как выглядит мой код:
Код: Выделить всё
import boto3
from boto3.dynamodb.types import TypeDeserializer
import panads as pd
connection = boto3.client(
'dynamodb',
**config # This contains my credentials
)
result = connection.execute_statement(Statement=query)
records = []
if result['Items']:
# TODO: Can parsing be optimized?
records.extend(parse_records(result['Items']))
while 'LastEvaluatedKey' in result:
result = connection.execute_statement(
Statement=query,
NextToken=result['NextToken']
)
records.extend(parse_records(result['Items']))
df = pd.json_normalize(records)
def parse_records(records: List[Dict]) -> Dict:
"""
Parses the records returned by the PartiQL query execution.
Args:
records (List[Dict]): A list of records returned by the PartiQL query execution.
Returns:
Dict: A dictionary containing the parsed record.
"""
deserializer = TypeDeserializer()
parsed_records = []
for record in records:
parsed_records.append({k: deserializer.deserialize(v) for k,v in record.items()})
return parsed_records
Подробнее здесь: https://stackoverflow.com/questions/788 ... via-python