Advertisement
YomoMan

main.ipynb

Mar 29th, 2023
1,045
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.39 KB | None | 0 0
  1. ################ ЯЧЕЙКА 1 ################
  2. import numpy as np
  3. import pandas as pd
  4. import os
  5.  
  6. import boto3
  7. import os
  8. from pathlib import Path
  9. ##########################################
  10.  
  11. ################ ЯЧЕЙКА 2 ################
  12. S3_CREDS = {
  13.     "aws_access_key_id": "........",
  14.     "aws_secret_access_key": "......",
  15. }
  16.  
  17. bucket = "test-bucket2"
  18.  
  19. def download_files(s3_client, bucket_name: str, local_path: str, file_name: str) -> None:
  20.     local_path = Path(local_path)
  21.  
  22.     local_path.mkdir(parents=True, exist_ok=True)
  23.  
  24.     file_path = Path.joinpath(local_path, file_name)
  25.     file_path.parent.mkdir(parents=True, exist_ok=True)
  26.     s3_client.download_file(
  27.         bucket_name,
  28.         file_name,
  29.         str(file_path)
  30.     )
  31.  
  32. def get_mean_value(input_data):
  33.     df = pd.read_csv(f'from-s3-folder/{input_data["file_name"]}')
  34.     return df[input_data['column_name']].mean()
  35. ##########################################
  36.  
  37. ########## ЯЧЕЙКА 3 для закрепа ##########
  38. input_data = dict(file_name='diabetes.csv', column_name='age')
  39.  
  40. client = boto3.client(
  41.     service_name='s3',
  42.     endpoint_url='https://storage.yandexcloud.net',
  43.     **S3_CREDS
  44. )
  45.  
  46. download_files(
  47.     client,
  48.     bucket,
  49.     "from-s3-folder",
  50.     input_data['file_name']
  51. )
  52.  
  53. output_data = get_mean_value(input_data)
  54. print(output_data)
  55. ##########################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement