Posts

Showing posts from August, 2022

SQL Server shortcut keys

  SQL Server Management Studio keyboard shortcuts - SQL Server Management Studio (SSMS) | Microsoft Docs

SQL Number Format

  Here’s an example: SELECT FORMAT(1, 'N'); Result: 1.00 In this case, I used  N  as the second argument. This is the  standard numeric format specifier  for Number. This particular format specifier ( N ) results in the output being formatted with integral and decimal digits, group separators, and a decimal separator with optional negative sign. This argument is case-insensitive, so either  N  or  n  is fine. Decimal Places Here’s another example, this time using  N1  to specify that we only want one decimal place: SELECT FORMAT(1, 'N1'); Result: 1.0 But you can also increase the number of decimal places too: SELECT FORMAT(1, 'N7'); Result: 1.0000000

Drop table if exists in SQL

Create temp table in SQL Server   drop table if exists #sfa_measurement into #sfa_measurement

Date_range in pandas

  Creating a   DataFrame   by passing a NumPy array, with a datetime index and labeled columns: In [5]: dates = pd . date_range ( "20130101" , periods = 6 ) In [6]: dates Out[6]: DatetimeIndex(['2013-01-01', '2013-01-02', '2013-01-03', '2013-01-04', '2013-01-05', '2013-01-06'], dtype='datetime64[ns]', freq='D') In [7]: df = pd . DataFrame ( np . random . randn ( 6 , 4 ), index = dates , columns = list ( "ABCD" )) In [8]: df Out[8]: A B C D 2013-01-01 0.469112 -0.282863 -1.509059 -1.135632 2013-01-02 1.212112 -0.173215 0.119209 -1.044236 2013-01-03 -0.861849 -2.104569 -0.494929 1.071804 2013-01-04 0.721555 -0.706771 -1.039575 0.271860 2013-01-05 -0.424972 0.567020 0.276232 -1.087401 2013-01-06 -0.673690 0.113648 -1.478427 0.524988

Read Parquet file in pandas

callplan_202205 = pd.read_parquet('../../ReportMart/Call_Plan/data/call_plan_202205.parquet', engine='pyarrow')

Case When in Numpy

 callplan['CH'] = np.where(callplan['CH'] == 'ER', 'Modern Off & Digital',                 np.where(callplan['CH'] == 'MF', 'Modern Off & Digital',                 np.where(callplan['CH'] == 'UF', 'Urban Off',                 np.where(callplan['CH'] == 'UN', 'Traditional On',                 np.where(callplan['CH'] == 'MN', 'Modern On',                 np.where(callplan['CH'] == 'RM', 'Rural On & Off',                 callplan['CH']                                               ))))))

WHERE or IF function in Numpy

Script union['CH'] = np.where(union['Invoice Type'] == 'Normal Sales', union['Channel Name'],'Wedding & Function') Explanation IF "Invoice Type" = "Normal Sales" then union['CH'] = union['Channel Name'] Else union['CH'] = "Wedding & Function"

LEFT function in pandas

 callplan['CH'] = callplan['Level1_Territory_Name'].str[:2]

Filter in pandas

union = union[union['Total HL']!=0]

Pivot table in pandas

 pivot2 = pd.pivot_table(union,                          index=['YM','Channel Name','SKU_x','Invoice Type'],                          values=['Document No_','Total HL'],                          aggfunc={'Document No_':pd.Series.nunique                                 ,'Total HL': np.sum})

Write into Excel by pandas

ExcelW = pd.ExcelWriter('Data/Volume.xlsx', engine='openpyxl', mode='a', if_sheet_exists='overlay') Volume_Agent.to_excel(ExcelW, sheet_name='Volume_Agent', index=False) ExcelW.close()

Groupby in Pandas

 Volume_Agent = union.groupby(['YM','AgentID','Channel Name','Invoice Type','Province',                                'SR_Territory','SR_Name'                               ,'Brand_y','Brand Segment','Brand Variants'                               ,'Pack Type','CH'], as_index=False)[['Total HL','Quantity']].sum()

Add new column as format yyyy-mm in pandas

 callplan['YM'] = callplan['Visited Date'].dt.strftime('%Y-%m')

Lorem ipsum is placeholder - sample text for designing project

  Lorem ipsum  is placeholder text commonly used in the graphic, print, and publishing industries for previewing layouts and visual mockups.

Convert String to Datetime "yyyy-mm-dd"

In publishing and graphic design, Lorem ipsum is a placeholder text commonly used to demonstrate the visual form of a document or a typeface without relying on meaningful content. Lorem ipsum may be used as a placeholder before final copy is available. It is also used to temporarily replace text in a process called greeking, which allows designers to consider the form of a webpage or publication, without the meaning of the text influencing the design. In publishing and graphic design, Lorem ipsum is a placeholder text commonly used to demonstrate the visual form of a document or a typeface without relying on meaningful content. Lorem ipsum may be used as a placeholder before final copy is ng of the text influencing the design. In publishing and graphic design, Lorem ipsum is a placeholder text commonly used to demonstrate the visual form of a document or a typeface without relying on meaningful content. Lorem ipsum may be used as a placeholder before final copy is available. It is also...