#Remove duplicate item from Python List
old_list = ['k','l','k','m','m','n','o']
new_list =[]
for element in old_list:
if element not in new_list:
new_list.append(element)
#print(new_list)
#['k', 'l', 'm', 'n', 'o']
#2nd Approach:
old_list = ['k','l','k','m','m','n','o']
#new_list = dict.fromkeys(old_list)
#{'k': None, 'l': None, 'm': None, 'n': None, 'o': None}
new_list = dict.fromkeys(old_list).keys()
#dict_keys(['k', 'l', 'm', 'n', 'o'])
new_list = list( dict.fromkeys(old_list).keys() )
print(new_list)
#['k', 'l', 'm', 'n', 'o']
To live a creative life we must lose the fear of being wrong.
Wednesday, December 20, 2023
Functional Programming and OOP Comparison Table
Basis For Comparison | Functional Programming | OOP |
Definition | Functional programming emphasizes an evaluation of functions. | Object-oriented programming is based on the concept of objects. |
Data | Functional programming uses immutable data. | Object-oriented uses mutable data. |
Model | Functional programming does follow a declarative programming model. | Object-oriented programming does follow an imperative programming model. |
Support | Functional Programming supports parallel programming. | Object-oriented programming does not support parallel programming. |
Execution | In Functional programming, the statements can be executed in any order. | In OOPs, the statements should be executed in a particular order. |
Iteration | In Functional programming, recursion is used for iterative data. | People use loops for iterative data in OOP. |
Element | The basic elements of functional programming are Variables and Functions. | The essential elements of object-oriented programming are objects and methods. |
Use | People use functional programming only when they have few things with more operations. | People use object-oriented programming when they have many things with few operations. |
Sunday, December 17, 2023
Dense_Rank with Group function
Source_Path: "E:\source_files\CUSTOMER_CGI.CSV"
sdate,custid,pname,region,pcategory,price
01-01-2019,111,pen,NY,stationary,10.00
01-01-2019,111,pencil,NY,stationary,40.00
01-01-2019,222,pen,NY,stationary,10.00
01-01-2019,333,pen,NY,stationary,10.00
01-01-2019,444,book,CT,stationary,55.00
01-01-2019,222,pen,NY,stationary,10.00
01-02-2019,333,pen,NY,stationary,10.00
01-02-2019,333,pen,NY,stationary,10.00
01-02-2019,111,slate,NY,stationary,40.00
01-02-2019,111,slate,NY,stationary,40.00
01-02-2019,555,bag,NY,stationary,100.00
01-03-2019,444,pen,CT,stationary,10.00
01-03-2019,444,pencil,CT,stationary,15.00
01-03-2019,444,pencil,CT,stationary,15.00
01-03-2019,444,pen,CT,stationary,10.00
01-03-2019,111,pen,NY,stationary,10.00
01-03-2019,111,pen,NY,stationary,10.00
01-04-2019,111,pen,NY,stationary,10.00
01-04-2019,222,pen(,NY,stationary,10.00
01-04-2019,333,pen,NY,stationary,10.00
01-04-2019,444,choco,CT,stationary,50.00
01-04-2019,444,choco,CT,stationary,50.00
SET LINES 100
ALTER SESSION SET NLS_DATE_FORMAT = 'DD-MM-YYYY';
select * from CUSTOMER_CGI ORDER BY SDATE ;
SDATE CUSTID PNAME REGION PCATEGORY PRICE
---------- ---------- ---------- ---------- ---------- ----------
01-01-2019 333 pen NY stationary 10
01-01-2019 222 pen NY stationary 10
01-01-2019 111 pencil NY stationary 40
01-01-2019 111 pen NY stationary 10
01-01-2019 444 book CT stationary 55
01-01-2019 222 pen NY stationary 10
01-02-2019 111 slate NY stationary 40
01-02-2019 111 slate NY stationary 40
01-02-2019 333 pen NY stationary 10
01-02-2019 333 pen NY stationary 10
01-02-2019 555 bag NY stationary 100
01-03-2019 444 pen CT stationary 10
01-03-2019 444 pencil CT stationary 15
01-03-2019 444 pencil CT stationary 15
01-03-2019 444 pen CT stationary 10
01-03-2019 111 pen NY stationary 10
01-03-2019 111 pen NY stationary 10
01-04-2019 111 pen NY stationary 10
01-04-2019 222 pen NY stationary 10
01-04-2019 333 pen NY stationary 10
01-04-2019 444 choco CT stationary 50
01-04-2019 444 choco CT stationary 50
By SQL Method :
Q1: --Get the custer detail who has done highest sales per day (datewise highest sales)
SELECT * FROM
( SELECT custid,
sdate,
SUM (price) AS total_price,
DENSE_RANK () OVER (PARTITION BY sdate ORDER BY SUM (price) desc) AS rnk --desc if u want maximum , asc if u want minimum
FROM CUSTOMER_CGI
GROUP BY sdate, custid ) tt
WHERE tt.rnk = 1 ;
Q2: --Get the custer detail along with date where the total sales price is/are the highest .
SELECT * FROM
( SELECT custid,
sdate,
SUM (price) AS total_price,
DENSE_RANK () OVER (ORDER BY SUM (price) desc) AS rnk --desc if u want maximum , asc if u want minimum
FROM CUSTOMER_CGI
GROUP BY sdate, custid ) tt
WHERE tt.rnk = 1
By Dataframe Method:
Subscribe to:
Posts (Atom)