Forum Discussion
Python in Power Query VS Code
- 5 months ago
py script
import pandas as pd import numpy as np df['DATE_ID'] = pd.to_datetime(df['DATE_ID']) df['Town-Citycode'] = df['Town-Citycode'].str[:9] df = df.sort_values(['Town-Citycode', 'DATE_ID']) df['diff'] = np.where(df.groupby('Town-Citycode')['SALECOUNT'].diff()>0, 'Up', 'Down') pvt = df.pivot_table(columns=['DATE_ID'], index=['Town-Citycode'], values=['SALECOUNT', 'diff'], aggfunc='sum') pvt.reset_index(inplace=True)When it comes to data visualization, DAX is often a more elegant alternative,
Why would you want to pivot the date column like that? That's antithetical to Power Query and Power BI. Your CSV file already seems to be in the best format.
Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
Do not include sensitive information. Do not include anything that is unrelated to the issue or question.
Please show the expected outcome based on the sample data you provided.
Need help uploading data? https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-p/963216
Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523