I have a dataframe with two columns : ID and Demographic_distribution. ID is just a number (ex:123456). demographic_impression has a list for each ID. here's an example of what you get in the demographic_distribution column for one ID :
ID : 123456
Demographic_distribution : {"age":"25-34","gender":"male","percentage":2.6e-5},{"age":"13-17","gender":"female","percentage":0.000102},{"age":"13-17","gender":"male","percentage":0.000153},{"age":"65+","gender":"unknown","percentage":0.002118},{"age":"55-64","gender":"female","percentage":0.114114},{"age":"45-54","gender":"male","percentage":0.106534},{"age":"35-44","gender":"female","percentage":0.220674},{"age":"35-44","gender":"male","percentage":0.168249},{"age":"55-64","gender":"male","percentage":0.076748},{"age":"65+","gender":"female","percentage":0.086192},{"age":"45-54","gender":"female","percentage":0.152144},{"age":"65+","gender":"male","percentage":0.056202},{"age":"35-44","gender":"unknown","percentage":0.009239},{"age":"55-64","gender":"unknown","percentage":0.002552},{"age":"45-54","gender":"unknown","percentage":0.004952}
You can see that there are 5 age groups, 3 genders and many percentages. I would like to split the demographic column into three different columns for each parameters. Let's not forget that these informations are liked to an ID in each row, otherwise it doesn't make sense. I tried .explode, but it didn't work.
Any idea how to do this ?
Related
I have 2 tables : rc_course and rc_resultat.
rc_resultat :
rc_course :
Tables should be joined on rc_resultat.course_id=rc_course.id
Here is the SQL query result I'm looking for with WHERE championnat_id=1
Explanation :
rc_resultat.id is the user ID, must be unique (not 2 rows with the same)
R1,R2,...etc are 1 colum per course_id (the column name could be the course_id, no matter, but if a user doesn't have a value for this column it should be handled). Important : as you can see, one course_id can have many points so it should be the SUM of these values.
TOTAL is the total amount of the row.
To understand better, it's a championship points calculation based on multiple events where users participated or not.
in MYSQL how to get specific columns name for example:
i have following cols in databse
ID
NAME
ADDRESS
MOBILE
below query shows all the above columns name but i want to get all cols except ID and MOBILE.
SHOW COLUMNS FROM CONSIGNEE
Use WHERE to filter FIELD column
SHOW COLUMNS FROM CONSIGNEE WHERE FIELD NOT IN ('ID', 'MOBILE')
I have tables that contain common column.
A : car, banana, monkey
B : banana, dragon, snail
C : shoes, socks, banana
As you can see, column banana is the common column. Same name, same data type, (int).
And I want to do some search work span these table.
For example,
In A table, I want to find the rows that contains keyword 'Toyota' in column 'car'.
In B table, keyword 'evil snail' in column 'snail'
....
Like this.
Then, I'd like to retrieve the value of banana fields through two methods :
From the found rows of all tables
banana that can be found in found row in all tables.
So despite I can't even sketch about solution, two sql line is needed...
I kept think almost eight hours to solve this problem but only headache is get worsen..
I wonder someone could help this out...
To find all the A that contains the key word 'Toyota' in 'car' do:
SELECT * FROM A WHERE car like '%Toyota%';
Same for B and C. You should notice that the like is use in the case where we are checking if the column contains the value. To make an exact match you should use the equal to sign e.g. car='Toyota'.
For your second query type you want a result which is a dis-junctive in nature. So you should query each table and unite the result like:
SELECT a.banana FROM A a where a.banana=[VALUE]
UNION
SELECT b.banana FROM B b where b.banana=[VALUE]
UNION
SELECT c.banana FROM C c where c.banana=[VALUE];
I have a table name Vouchers in which i have three columns named "GroupName","LedgerName" and "Amount".
I have another Table named Accounts in which i have two columns "Name" and "Amount", now i want the column "Name" to have the the GroupName from the Vouchers Table and then all the LedgerName that have same GroupName to fall under that Record. The images explain my question asked above
Isn't this ORDER BY operation??
I don't think you can get your result in that format. But using ORDER BY operation you can get a similar output but with an extra column. :)
i have two tables "members" and "users".
I need with one query from this two tables get all users where condition is "name LIKE %Joy%".
How join in this situation two tables?
Tables:
users
id / name / age
1 joy 15
2 marko 26
members
id / name / level
1 peter 1
2 joyes 0
3 marko 1
Try with UNION. I added the first column so you can check later where that result came from (and create a link to the user's profile page for example).
(SELECT 'user' AS type, id, name FROM user WHERE name LIKE '%Joy%')
UNION
(SELECT 'member', id, name FROM member WHERE name LIKE '%Joy%')
It appears as though both tables essentially store information about the same kind of thing: people. I don't know what the difference is between a "user" and a "member" in your specific situation, but it sounds as though you might be better off having just one table "people" with a bit column specifying whether the person is a user or a member.