Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I am trying to extract "Purchase Id: XXXXXXXX" for the following rows in a pandas dataframe but I am not sure of the correct regex expression to select starts with Purchase Id and ends after the digits.
What I have now:
Description
"Online order Purchase Id: 14527903 Charge Id: 11111111"
"Online order Purchase Id: 90762134 Charge Id: 33345872"
The desired result:
Description
Purchase Id: 14527903
Purchase Id: 90762134
Try this to match any number of digits after Product Id: :
df['Description'].str.extract('(Purchase Id: \d+)')
or this to match 8 characters after Product Id: :
df['Description'].str.extract('(Purchase Id: .{8})')
Output:
0
0 Purchase Id: 14527903
1 Purchase Id: 90762134
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed last month.
Improve this question
I would like to know if there is another way to insert a variable in prepare preventing sql injection
I tried that way but it leaves cause vulnerability i am using QSqlQuery class from qt to perform queries
query.prepare("update coins_tb set VALUE='"+QString::fromStdString(match.str(2))+"' where TOKEN='"+QString::fromStdString(match.str(1))+"'");
Here is an example from Qt docs:
QSqlQuery query;
query.prepare("INSERT INTO person (id, forename, surname) "
"VALUES (:id, :forename, :surname)");
query.bindValue(":id", 1001);
query.bindValue(":forename", "Bart");
query.bindValue(":surname", "Simpson");
query.exec();
And with your query it looks like:
query.prepare("update coins_tb set VALUE=:value where TOKEN=:token");
query.bindValue(":value", QString::fromStdString(match.str(2)));
query.bindValue(":token", QString::fromStdString(match.str(1)));
query.exec();
I have a table with 3 columns: CLIENT_ID, STORE_ID and MADE_PURCHASE. Basically I'm trying to get a list of CLIENT_ID and an array of STORE_ID where a customer made a purchase. For the following data, here is the expected result:
DATA:
CLIENT_ID
STORE_ID
MADE_PURCHASE
1
a
YES
1
b
YES
1
c
YES
2
a
YES
2
b
NO
2
c
YES
3
a
NO
3
b
NO
3
c
NO
Expected result:
CLIENT_ID
STORE_ID
1
a,b,c
2
a,c
I was able to achieve the desired result by creating a query to filter out lines where MADE_PURCHASE = 'NO'. Then I created a list in the report. The first column is CLIENT_ID then I insert a repeater in the second column that contains STORE_ID.
The problem is that the repeater slows my report by a factor about equal to the number of CLIENT_ID retrieved. For example if I run the query without a repeater and it returns 10 unique CLIENT_ID in 10 seconds, then adding the repeater slows the report to 100 seconds. As soon as I enter more than a few hundred CLIENT_ID in the prompt the report takes multiple hours to run.
I tried editing the master-detail relatioship between the list and the repeater without much change. Anyone has any idea how I could make it run faster?
P.S. I know the desired output format is not ideal but the goal is to mimic a legacy report that was built on excel using concatenate on STORE_ID, as such, the client wants to keep the original format.
You can try to edit the FM - Governors with the parameter (DQM) Master-Detail Optimization with "Cache Relaional Detail Query".
I am working on a project where I have a data set that includes ID, Question Name, Answer. This is all being built into Power BI report. I am trying to get the count of distinct ID's where for each ID or entity I have multiple answers.
For example I have Session ID 12345, and for this session we conduct an outcome survey that asks the questions 'What was your focus area?' and 'Overall how satisfied were you with your coach?'
Now I have a group of Sessions, all unique, and this group has Answered 'Healthy Eating to the first question (focus area). Within this group I want to find the count that has answered 'Satisfied' or 'Very Satisfied'.
I have already gotten the count for the group of Sessions that have answered healthy eating:
found Session Count first:
Session Count = Calculate(distinctcount(SessionID))
Then applied filter for Healthy Eating:
healthy eating = calculate([Session Count]), FILTER(Table1, Table1[Answer]="Healthy Eating"))
Now I thought I could get the Satisfied and Very Satisfied count by using the following:
HE Satisfied = calculate([healthy eating]), (FILTER(Table1, Table1[Answer] = "Satisfied" || Table1[Answer]= "Very Satisifed"))
I am getting blank value.
Table struture is like the below example:
SessionID QuestionName Answer
123 What was your focus area? Healthy Eating
123 Overall how satisfied were you with Very Satisfied
your coach?
124 What was your focus area? Healthy Eating
124 Overall how satisfied were you with Very Satisfied
your coach?
125 What was your focus area? Healthy Eating
125 Overall how satisfied were you with Not Satisfied
your coach?
So in the case above, I have a count of 3 Sessions for Healthy Eating, my satisfaction rate would be 2/3 or 67% in this case. The Math is easy I just need to figure out how to get the Count of 2 from the above.
Thanks for any help.
I think you're going to have to do more data wrangling for this to work.
In your example there's no relationship between session ID 123 regarding focus and session ID 123 regarding coach satisfaction, therefore when you calculate healthy eating you get the correct count but when you try to apply that to the satisfaction levels you get blanks.
If you separate the data into 2 tables one with all "what was your focus area? " rows and the other with the "Overall how satisfied were you with... " rows and then create a relationship between the two on the session ID you'll get the result you're looking for with
HE Satisfied = CALCULATE([healthy eating], coach[answer] = "Satisfied" || coach[answer] = "Very Satisfied")
I am trying to create a spreadsheet that has options for closing customers.
If the cell says "Approved" then the Estimated Quote should appear in the "Closed Deal" column. If it shows "Denied" it shows a "0" dollar value. Pending will also show a "0" value.
If A1 is the cell and ColumnB the Closed Deal column:
=if(A1="Approved","the Estimated Quote",if(or(A1="Denied",A1="Pending"),"$0","?"))
This can be copied down to act the same on A2 etc. "the Estimated Quote" should perhaps be a cell reference.
This question already has answers here:
How do I make an UPDATE while joining tables on SQLite?
(2 answers)
Closed 6 years ago.
My select statement finds the records I want to update- Now I want to invert (multiply x -1) the adjusted_sentiment score for only these records. Here is the select statement:
Select players.name, fbposts.company, fbposts.post_id, reactions.reaction,
fbposts_comments.adjusted_sentiment, fbposts_comments.message, fbposts.message from fbposts
join reactions on reactions.post_id = fbposts.post_id
join players on players.id = reactions.id
join fbposts_comments on fbposts_comments.post_id = fbposts.post_id
where adjusted_sentiment > 0 and reactions.reaction like "ANGRY" and
reactions.id = fbposts_comments.comment_id group by fbposts.post_id
This returns records like:
Baktiyar Romanov,WorldOfWanderlust,387990201279405_994067924004960,ANGRY,0.5965,probably fed very ill-mannered rich man
Sheridan Toms,australiapost,96085205666_10153485650690667,ANGRY,0.04676666666666666,Seriously? You can't even get an express post parcel from victoria to wa in under 2 weeks!!!! Super annoyed
Robert Smissen,australiapost,96085205666_10153487649895667,ANGRY,0.8555,Looks like Australia Post is using Diggers' letters to gain some reflected glory
Eve Ismaiel,australiapost,96085205666_10153500759100667,ANGRY,0.1133333333333333,"Ha ha... Present $20, postage $30!!!"
What I want to do is invert the adjusted_sentiment score. For example in the first record, the adjusted_sentiment score is 0.5965 I want to update that to -0.5965
BTW my queries and updates will be done via Python2.7... One thought I working on now is to create a list from the query above then use that list to create a series of update statements.
Below query will give you the expected output
update fbposts_comments set adjusted_sentiment = -adjusted_sentiment where post_id in (Select fbposts_comments.post_id from fbposts
join reactions on reactions.post_id = fbposts.post_id
join players on players.id = reactions.id
join fbposts_comments on fbposts_comments.post_id = fbposts.post_id
where adjusted_sentiment > 0 and reactions.reaction like "ANGRY" and
reactions.id = fbposts_comments.comment_id group by fbposts.post_id)