Forum Discussion
Anonymous
7 years agoNot applicable
Prompts to Power BI using Python scripts
Hi, I am trying to compare software version in 2 columns and return a third column based on the results and in order to do this I am using Python. The script works perfectly fine in Jupyter noteb...
- 7 years ago
Anonymous ,
Please import the csv to power bi at first. Then implement the python script. The script works well on my side.
Community Support Team _ Jimmy Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
7 years agoNot applicable
import pandas as pd
import numpy as np
dataset= pd.read_csv("abhicomp.csv")
v1 = dataset['Latest Packaged Version'].fillna('').tolist()
v2 = dataset['Version'].fillna('').tolist()
def change_string_to_ascii(v12):
fin_list = []
for i in v12:
if(i.isdigit()):
fin_list.append(i)
else:
#print(i)
fin_list.append(ord(i))
#fin_str = "".join(fin_list)
return fin_list
def compare_list(list1, list2):
result_list = []
for i,j in zip(list1, list2):
if (i == "" or j == ""):
if(i == ""):
result_list.append("Upgraded")
else:
result_list.append("Not Upgraded")
continue
if(len(i) > len(j)):
result_list.append("Not Upgraded")
continue
elif(len(i)< len(j)):
result_list.append("Upgraded")
continue
else:
i_arr = i.split(".")
j_arr = j.split(".")
i_arr_dl = change_string_to_ascii(i_arr)
j_arr_dl = change_string_to_ascii(j_arr)
count = 0
for i_val, j_val in zip(i_arr_dl, j_arr_dl):
count+=1
if(i_val > j_val):
result_list.append("Not Upgraded")
break
elif(i_val == j_val):
#print(count, len(i_arr))
if(count == len(i_arr)):
#print("added")
result_list.append("Upgraded")
else:
continue
elif(i_val < j_val):
result_list.append("Upgraded")
break
return result_list
version_check_list = compare_list(v1, v2)
dataset['res'] = version_check_listHere you go with the formatted code. It is pretty similar to what I posted on earlier just with few more added corner cases. Thank you again for the help.
v-yuta-msft
7 years agoCommunity Support
Anonymous ,
Please import the csv to power bi at first. Then implement the python script. The script works well on my side.
Community Support Team _ Jimmy Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.