Skip to content

Instantly share code, notes, and snippets.

@ultraian
Last active August 7, 2017 04:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ultraian/a7c8a38682da4cc0d11c910ef4110e17 to your computer and use it in GitHub Desktop.
Save ultraian/a7c8a38682da4cc0d11c910ef4110e17 to your computer and use it in GitHub Desktop.
pivot automation
############### Not completed!!!!#################
# -*- coding: utf-8 -*-
import cx_Oracle as co
import pandas as pd
from pandas import DataFrame
import pandas.io.sql as sql
import numpy as np
print("Job Start")
# Oracle Connect
con = co.connect(###connection information deleted###)
CategoryText = "TestCategory"
pivot_mst = sql.read_sql("select * from pivot_mst where category='" + CategoryText + "' and use_yn='Y' order by seq_no",con)
Sql_Result=DataFrame()
Pivot_Source=DataFrame()
Pivot_Title=DataFrame()
pivot_mst['TAB_SHIFT'] = pivot_mst.TABLE_NAME.shift(1)
for index, row in pivot_mst.iterrows():
Value_Cols = []
Func_Dict = {}
if row['TABLE_NAME'] != row['TAB_SHIFT']:
# print(row.TABLE_NAME)
Sql_Result = sql.read_sql("select * from " + row.TABLE_NAME,con)
# print(Sql_Result)
Row_Criteria = [row.ROW_CRITERIA]
Column_Criteria = [row.COLUMN_CRITERIA]
Filter_Criteria = [row.FILTER_CRITERIA]
# print(type(Row_Criteria))
for column in pivot_mst:
if column.find('VALUE_COL')>=0 and row[column] != None:
Value_Cols.append(row[column])
Value_Text = row[column]
if column.find('FUNC_CRITERIA')>=0 and row[column] != None:
Func_Dict[Value_Text] = [row[column]] # <------------ Here is problem!!!!
# for column in pivot_mst:
print("Value_Cols : " , Value_Cols)
print("Func_Dict : " , Func_Dict)
# oracle close
con.close()
##########Print Result###################
Value_Cols : ['sales_qty', 'buyer_cnt']
Func_Dict : {'sales_qty': ['sum'], 'buyer_cnt': ['count,sum']}
##########Print Result###################
#########I want below result############
Func_Dict : {'sales_qty': [sum], 'buyer_cnt': [count,sum]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment