JungHulk / Hulk-Engineering

1 stars 0 forks source link

Pickle maker #6

Open JungHulk opened 1 year ago

JungHulk commented 1 year ago

Table_Export.py

import os
from win32com.client import Dispatch
import pandas as pd
import pickle

excel = Dispatch('excel.Application')  # win32com.client로 excel call
openfiledir = os.getcwd() + '\\' # 현재 폴더 위치 
filename = 'Pipetable.xls'
# 현재 폴더 위치의 해당 파일명의 .xls 파일 open

wb = excel.Workbooks.Open(openfiledir + filename)

ws = wb.Worksheets("Pipetable")
StartCell = ws.Range("B2")
Data = ws.Range(StartCell.Address).CurrentRegion.Value

ColName = list(Data[3])

# =============================================================================
# for i in range(len(Data[1])):
#     if Data[3][i] is not None:
#         cc = str(Data[3][i])
#     if Data[4][i] is not None:
#         kk = cc + "_" + Data[4][i]
#     else:
#         kk = cc
#     ColName.append(kk)
# =============================================================================

ColName[2]="Out_Dia"
df1 = pd.DataFrame(Data, columns = ColName)

df1.drop([0,1,2,3,4], inplace = True)

IndName = df1['(ND)']
df1.index = IndName

df1.drop(['(NPS)','(ND)'], axis = 1, inplace = True)

ws1 = wb.Worksheets("Orifice") # Sheet 불러오기
StartCell1 = ws1.Range("B1")   # B2 셀 선택
Data1 = ws1.Range(StartCell1.Address).CurrentRegion.Value # 선택 셀 + ctrl all

StartCell3 = ws1.Range("H1")   # B2 셀 선택
Data3 = ws1.Range(StartCell3.Address).CurrentRegion.Value # 선택 셀 + ctrl all

# Spring loaded type
df2 = pd.DataFrame(Data1, columns = Data1[1]) # Dataframe 생성

IndName1 = df2['Designation'] # 행 이름 선정

#IndName1 = IndName1.fillna(method='ffill')
IndName1.fillna(method='ffill',inplace = True) # missing value 앞 값으로 채우기.
df2.index = IndName1
df2.drop(['Spring', 'Designation'], inplace = True)
df2.drop(['Designation'], axis=1, inplace = True)

# Pilot Operated type
df3 = pd.DataFrame(Data3, columns = Data3[1]) # Dataframe 생성

IndName3 = df3['Designation'] # 행 이름 선정

#IndName1 = IndName1.fillna(method='ffill')
IndName3.fillna(method='ffill',inplace = True) # missing value 앞 값으로 채우기.
df3.index = IndName3
df3.drop(['Pilot', 'Designation'], inplace = True)
df3.drop(['Designation'], axis=1, inplace = True)

'''
DataSet = dict()

for NoSheet in [4,5,6,7]:
    ws = wb.Worksheets(NoSheet)
    StartCell = ws.Range("A1:A1000").Find("Time")
    print(StartCell.Address)
    while conf is not None:
        NoData += 1
        Data = ws.Range(StartCell.Address).CurrentRegion.Value

        if NoData == 1:
            Data = Data[2:]

        TempData = pd.DataFrame(Data) 

        for i in range(len(TempData)):
            newVal = dt.datetime.strptime(TempData.loc[i,0],"%Y-%m-%d %p %I:%M:%S")
            TempData.loc[i,0] = newVal

        TempData.columns = ColName
        TempData.drop('Data Case', axis = 1, inplace = True)

        globals()['Data_{}'.format(NoSheet)+'_{}'.format(NoData)] = TempData

        if NoSheet >=6:
            DataSet['Data_{}'.format(NoSheet-3)+'_{}'.format(NoData+4)] = \
                globals()['Data_{}'.format(NoSheet)+'_{}'.format(NoData)]
        else:
            DataSet['Data_{}'.format(NoSheet-3)+'_{}'.format(NoData)] = \
                globals()['Data_{}'.format(NoSheet)+'_{}'.format(NoData)]
        NextCell = ws.Range(StartCell.Address).End(-4121).Offset(3,)
        StartCell = NextCell
        conf = StartCell.Value
    conf, NoData = 1, 0
'''
with open('Pipetable.p','wb') as file:
    pickle.dump(df1, file)

with open('Ori_Spring.p','wb') as file:
    pickle.dump(df2, file)

with open('Ori_Pilot.p','wb') as file:
    pickle.dump(df3, file)

excel.Quit()
JungHulk commented 1 year ago

Unit conv

# -*- coding: utf-8 -*-
"""
Created on Thu Jan 26 08:55:44 2023

@author: seungj.jung
"""

# -*- coding: utf-8 -*-
"""
Created on Thu Jan 19 15:39:48 2023

@author: seungj.jung
"""

#### Excel Data base 만들기
import os
import pandas as pd
import pickle
import numpy as np

# excel = Dispatch('excel.Application')  # win32com.client로 excel call
openfiledir = os.getcwd() + '\\' # 현재 폴더 위치 
filename = 'Unitconv.xlsx'  # 현재 폴더 위치의 해당 파일명의 .xls 파일 open

unit = np.array(["length", "area", "volume"])
for i, n in enumerate(unit):
    globals()['df_{}'.format(n)] = pd.read_excel(openfiledir + filename, sheet_name = n)   # 각 sheet name 으로 dataframe 만들기
    globals()['Indname_{}'.format(n)] = globals()['df_{}'.format(n)][format(n)]            # Dataframe 별 index 지정
    globals()['df_{}'.format(n)].index = globals()['Indname_{}'.format(n)]                 # Dataframe 에 index 설정
    globals()['df_{}'.format(n)].drop(format(n), axis = 1, inplace = True)                 # Dataframe 첫 열 삭제

    # for 문으로 저장하는건??

# df_length = pd.read_excel(openfiledir + filename, sheet_name = "length")
# Indname_length = df_length["length"]
# df_length.index = Indname_length

# df_length.drop('length', axis =1, inplace = True)

with open('Unitconv_length.p','wb') as file:
    pickle.dump(df_length, file)

with open('Unitconv_area.p','wb') as file:
    pickle.dump(df_area, file)    

with open('Unitconv_volume.p','wb') as file:
    pickle.dump(df_volume, file)
JungHulk commented 1 year ago

air prop

# -*- coding: utf-8 -*-
"""
Created on Thu Jan 19 15:39:48 2023

@author: seungj.jung
"""

#### Excel Data base 만들기
import os
import pandas as pd
# from pandas import Series
import pickle

# excel = Dispatch('excel.Application')  # win32com.client로 excel call
openfiledir = os.getcwd() + '\\' # 현재 폴더 위치 
filename = 'Air_properties.xlsx'  # 현재 폴더 위치의 해당 파일명의 .xls 파일 open

df = pd.read_excel(openfiledir + filename)
IndName = df['Temperature']
IndName[0] = "(Units)"
df.index = IndName    # Index 지정

df.drop([1], inplace = True)
df.drop(['Unnamed: 0','Temperature'], axis = 1, inplace = True)
df.drop(df.index[1], inplace = True)
ColName = df.columns  # Column 지정

with open('Air_prop.p','wb') as file:
    pickle.dump(df, file)