import pandas as pd
from typing import final
from venv import create
import multiprocessing
import base64
import os
import sys
import pymysql
import requests
from sqlalchemy import create_engine
import boto3
from decimal import Decimal
import json
def mul424(x):
x = x * 424
return x
dynamodb = boto3.resource('dynamodb', region_name='ap-northeast-2', aws_access_key_id='AKIAYAINYQ65U5LTPSQ7', aws_secret_access_key='')
table = dynamodb.Table('BUILDINGENERGY')
df = pd.read_csv("C:/Users/TSM/buildingenergy.csv",sep =',',encoding='utf-8',names=['date','addr','electricity','gas','count'],header=0,low_memory=False)
df = df.astype({'date':'str','addr':'str','electricity':'int','gas':'int','count':'int'}, errors='ignore')
df['gas'] = df['gas'].astype('Int64')
df = df.fillna(0)
df['gas_co2'] = df['gas'].apply(mul424)
df['electricity_co2'] = df['electricity'].apply(mul424)
df['energy_sum'] = df['gas'] + df['electricity']
df['co2_sum'] = df['gas_co2'] + df['electricity_co2']
df = df.fillna(0)
df = df.sort_values(by=['date','addr'])
print(df)
with table.batch_writer() as batch:
for index, row in df.iterrows():
batch.put_item(json.loads(row.to_json(), parse_float=Decimal))
gas소비량 NaN값 그냥 0으로 처리