Adding a new Column with specific Values Python - multiple-columns

enter image description here
I have a DataFrame named "Players_S". I would like to create a new column "Star_Ratings". My new column should include ratings based on a certain condition.
"Ratings" equal or less than 20 should be "1", "Ratings" between 21 and 40 should be "2, "Ratings" between 41 and 60 should be "3", Ratings" between 61 and 80 should be "4" and Ratings" between 81 and 100 should be "5".
I would like these new ratings in a new column "Star_Ratings". And my second question is can change my column position?
Thanks everyone.

Related

Find similar users

I have a table with thousands of rows.
Sample data:
user_id ZIP City email
105 100051 Lond. jsmith#hotmail.com
382 251574 jgjefferson#gmail.com
225 0100051 London john.smith#hotmail.com
I need to compare every user with the others, to be able to know which ones are similar.
In the example given, the user 105 and 225 are almost the same, so the expected result would be a column of a new id that matches the two of them, like this:
user_id ZIP City email new_id
105 100051 Lond. jsmith#hotmail.com 105
382 251574 jgjefferson#gmail.com 382
225 0100051 London john.smith#hotmail.com 105
How would I compare every field with the others, and know how to compare them, like clustering, for example?
Your emails:
email<-c("jsmith#hotmail.com","jgjefferson#gmail.com","john.smith#hotmail.com")
Distance between emails:
dist<-stringdistmatrix(email,email,method="jw")
dist[dist==0]<-1
Minimum distance between emails:
cbind(email,email_near=email[apply(dist, 1, which.min)],dist=apply(dist, 1, FUN=min))
email email_near dist
[1,] "jsmith#hotmail.com" "john.smith#hotmail.com" "0.208754208754209"
[2,] "jgjefferson#gmail.com" "jsmith#hotmail.com" "0.281746031746032"
[3,] "john.smith#hotmail.com" "jsmith#hotmail.com" "0.208754208754209"
After that I suggest to use a threshold on dist to identify closest emails and then compute the new_ID.

How to compare values from stored in the same table with qlikview?

being new to qlikview Im a litle confused with I should do in sql and what qlik provides out of the box.
Lets suppose I have a table similar to this :
id Status type value quantity dat_s Area
1 Activo A 10 10 20171001 Norte
2 Activo B 20 20 20171001 Norte
3 Activo C 15 15 20171001 Sul
4 Fechado A 5 5 20171101 Norte
5 Activo B 20 20 20171101 Norte
6 Activo D 5 5 20171101 Sul
7 Activo D 5 5 20170901 Sul
Id like to compare a table with itself, but only the likes from selected dates, lets imagine, data A = 20171001 and date B= 20171001 (these should be user defined via an input field or whatever) the comparison id like to do is for example :
Type CountDateA ValDateA CountDateB ValDateB valuediff
A 1 100 1 25 -75
B 1 400 1 400 0
C 1 225 0 0 -225
D 0 0 1 25 25
or
Area ValDateA ValDateB valuediff
Norte 500 425 -75
Sul 225 25 -200
I was planing to duplicate the table and use different field names for the same data leaving half empty but I hope there is a more elegant way
Thanks all.
just needed to load the table and then the calculations of the clumns would be :
Sum(< Status ={$('Activo')}, dat ={$(20171001)} qty*val)
Still quite confused with your problem. Qlikview's power relies (in few words) on building graphs or tables that are automatically updated depending on selected filters. In your example, I guess, that filter would be the date (or dates) the user selects. Hence, you wouldn't need to define columns like ValDateA, ValDateB etc. In your case however, it seems that you want to compare EXACTLY two dates, so you could define those columns, each of them depending on different date pickers. This being said, I'll show you how I would approach your problem although I'm not really sure whether I understood well:
I assume you read your data correctly so you have the first data table on memory (with the fields: id Status type value quantity dat_s Area)(note: be careful and consistent with capital letters)
Create a table chart with dimension "type" (which will autofilter each row expression) and with these expressions:
Count(distinct{< Status = {"Activo"}, date_s= {"$(vDate1)"} >} id) //how many rows in active state for date1 (vDate1 is a variable assigned to the first date picker)
Sum({< Status = {"Activo"}, date_s= {"$(vDate1)"} >} value*quantity)
Same as expression 1 but using $(vDate2)
Same as expression 2 but using $(vDate2)
In Qlikview you can just write Column(4) - Column(2), in QlikSense you would need to write the whole expressions 2 and 4 again and subtract the sums.

How to get custom rows in Pentaho?

I have one table with some information.
Name Age Address
Tejas 20 xyz
Jeffie 21 por
jason 19 brazil
This table i get from query.I want to show row which has age less than 20 with green and greater than 20 is red.(Note:Whole row should get the color).Is there Addins for tables for such scenario? Can anyone help me?

Multiple Word Text-Search on MySQL,Returning Number Before Specified Word

I wanna ask, I have a table that contain a column that contain text.For example :
Table name : Table_Books ||
Table Columns : Text, Total_Books, Total_Paper
Example text in column Text : 146 books were published, 82 books and
46 papers were released
Now,I want to get the number in front of every word books and paper in each row of column Text.
The result of the query in Total_Books will be : 228 (because
we find 146 and 82 before word books in column Text) The result of the
query in Total_Paper will be : 46 (because we find 46 before
word papers in column Text)
Can anyone help me how the query is? I dont know how to check if there's more than one books/paper in text of each row.
Thank you so much for the help :D

What would be the best practice to store multiple 2 digit dataset in MySql server

Let say i want to store several dataset ie
78 94 33 22 14 55 18 10 11
44 59 69 79 39 49 29 19 39
And later on i would like to be able run queries that will determine the frequency of certain number. What would be the best way to this? What would be table structure to make a fast query.
Please be specific as you can be.
To get the counts, you can run a query such as:
SELECT value, COUNT(*) from table_of_values GROUP BY value
Placing an index on the single integer value column is pretty much all you can do to speed that up.
You could of course also just keep a table with every two-digit value and a count. You will have to pre-fill the table with zero counts for every value.
Then increment the count instead of inserting:
UPDATE table_of_values SET count = count + 1 WHERE value = (whatever)