Support
Quality
Security
License
Reuse
Coming Soon for all Libraries!
Currently covering the most popular Java, JavaScript and Python libraries. See a SAMPLE HERE.
kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
Run wireshark, filter by: tcp.port == 81 && http
Run game and wait for loading menu (lobby)
Looking for something like "/userproxy?provider=steam&.." in wireshark and open it (by left click)
Copy Value from middle frame, it's must be more 450 symbols (468 for me)
How to store dictionary inside defaultdict(list)
from ast import literal_eval
# create cartesian product of categories and suggestions for each record,
# and calculate value_counts
z = pd.merge(
df['category'].apply(literal_eval).explode(),
df['suggestions'].apply(literal_eval).explode(),
left_index=True,
right_index=True).value_counts()
# convert to nested dict
d = {l: z.xs(l).to_dict() for l in z.index.levels[0]}
d
{'ART_AND_DESIGN': {'flipaclip': 39,
'mehndi design': 28,
'ibis paint x': 22,
'u launcher lite': 21,
'poster maker': 20,
'poster maker design app free': 20,
'ibis paint': 18,
'mehndi design 2021': 18,
'mehandi ka design': 18,
'u launcher': 18,
...
dictionary = defaultdict(dict)
for i in range(df.shape[0]):
...
-----------------------
from ast import literal_eval
# create cartesian product of categories and suggestions for each record,
# and calculate value_counts
z = pd.merge(
df['category'].apply(literal_eval).explode(),
df['suggestions'].apply(literal_eval).explode(),
left_index=True,
right_index=True).value_counts()
# convert to nested dict
d = {l: z.xs(l).to_dict() for l in z.index.levels[0]}
d
{'ART_AND_DESIGN': {'flipaclip': 39,
'mehndi design': 28,
'ibis paint x': 22,
'u launcher lite': 21,
'poster maker': 20,
'poster maker design app free': 20,
'ibis paint': 18,
'mehndi design 2021': 18,
'mehandi ka design': 18,
'u launcher': 18,
...
dictionary = defaultdict(dict)
for i in range(df.shape[0]):
...
-----------------------
from ast import literal_eval
# create cartesian product of categories and suggestions for each record,
# and calculate value_counts
z = pd.merge(
df['category'].apply(literal_eval).explode(),
df['suggestions'].apply(literal_eval).explode(),
left_index=True,
right_index=True).value_counts()
# convert to nested dict
d = {l: z.xs(l).to_dict() for l in z.index.levels[0]}
d
{'ART_AND_DESIGN': {'flipaclip': 39,
'mehndi design': 28,
'ibis paint x': 22,
'u launcher lite': 21,
'poster maker': 20,
'poster maker design app free': 20,
'ibis paint': 18,
'mehndi design 2021': 18,
'mehandi ka design': 18,
'u launcher': 18,
...
dictionary = defaultdict(dict)
for i in range(df.shape[0]):
...
PHP Fatal error: Uncaught Error: Call to a member function prepare()
public function checkHasAdmin($chat_id)
{
$db = new Database();
$sql = "SELECT * FROM table_admin WHERE chat_id = ?";
return $db->select($sql,[$chat_id]);
}
-----------------------
;extension=pdo_firebird
extension=pdo_mysql
;extension=pdo_oci
;extension=pdo_odbc
;extension=pdo_pgsql
extension=pdo_sqlite
;extension=pgsql
;extension=shmop
Flutter Tabs "Horizontal viewport was given unbounded height"
LayoutBuilder(
builder: (_, BoxConstraints viewportConstraints) {
return SingleChildScrollView(
child: ConstrainedBox(
constraints: BoxConstraints(
minHeight: viewportConstraints.maxHeight,
),
child: Column(),
);
},
),
-----------------------
Container(
height: MediaQuery.of(context).size.height,
child: TabBarView(
children: [
Icon(Icons.directions_car),
Icon(Icons.directions_car),
Icon(Icons.directions_car)
],
),
)
My bot doesn't give role, but it doesn't send error
@client.event
async def on_raw_reaction_add(payload): # We use payload
guild = client.get_guild(payload.guild_id) # Define the guild
member = get(guild.members, id=payload.user_id) # Get the member from the guild
# channel and message IDs should be integer:
if payload.channel_id == Channel_ID and payload.message_id == Message_ID: # Inser your ID's
if str(payload.emoji) == "YourEmoji":
role = get(payload.member.guild.roles, name='RoleName') # ID also possible.
if role is not None:
await payload.member.add_roles(role)
@client.event
async def on_raw_reaction_add(self, payload):
guild = client.get_guild(payload.guild_id)
member = get(guild.members, id=payload.user_id)
if payload.channel_id == Channel_ID and payload.message_id == Message_ID:
if str(payload.emoji) == "YourEmoji":
role = get(payload.member.guild.roles, name='RoleName') # Or id='RoleID'
else:
role = get(guild.roles, name=payload.emoji)
if role is not None:
await payload.member.add_roles(role) # Add the role
-----------------------
@client.event
async def on_raw_reaction_add(payload): # We use payload
guild = client.get_guild(payload.guild_id) # Define the guild
member = get(guild.members, id=payload.user_id) # Get the member from the guild
# channel and message IDs should be integer:
if payload.channel_id == Channel_ID and payload.message_id == Message_ID: # Inser your ID's
if str(payload.emoji) == "YourEmoji":
role = get(payload.member.guild.roles, name='RoleName') # ID also possible.
if role is not None:
await payload.member.add_roles(role)
@client.event
async def on_raw_reaction_add(self, payload):
guild = client.get_guild(payload.guild_id)
member = get(guild.members, id=payload.user_id)
if payload.channel_id == Channel_ID and payload.message_id == Message_ID:
if str(payload.emoji) == "YourEmoji":
role = get(payload.member.guild.roles, name='RoleName') # Or id='RoleID'
else:
role = get(guild.roles, name=payload.emoji)
if role is not None:
await payload.member.add_roles(role) # Add the role
-----------------------
@client.event
async def on_raw_reaction_add(payload): # We use payload
guild = client.get_guild(payload.guild_id) # Define the guild
member = get(guild.members, id=payload.user_id) # Get the member from the guild
# channel and message IDs should be integer:
if payload.channel_id == Channel_ID and payload.message_id == Message_ID: # Inser your ID's
if str(payload.emoji) == "YourEmoji":
role = get(payload.member.guild.roles, name='RoleName') # ID also possible.
if role is not None:
await payload.member.add_roles(role)
@client.event
async def on_raw_reaction_add(self, payload):
guild = client.get_guild(payload.guild_id)
member = get(guild.members, id=payload.user_id)
if payload.channel_id == Channel_ID and payload.message_id == Message_ID:
if str(payload.emoji) == "YourEmoji":
role = get(payload.member.guild.roles, name='RoleName') # Or id='RoleID'
else:
role = get(guild.roles, name=payload.emoji)
if role is not None:
await payload.member.add_roles(role) # Add the role
-----------------------
@client.event
async def on_raw_reaction_add(payload): # We use payload
guild = client.get_guild(payload.guild_id) # Define the guild
member = get(guild.members, id=payload.user_id) # Get the member from the guild
# channel and message IDs should be integer:
if payload.channel_id == Channel_ID and payload.message_id == Message_ID: # Inser your ID's
if str(payload.emoji) == "YourEmoji":
role = get(payload.member.guild.roles, name='RoleName') # ID also possible.
if role is not None:
await payload.member.add_roles(role)
@client.event
async def on_raw_reaction_add(self, payload):
guild = client.get_guild(payload.guild_id)
member = get(guild.members, id=payload.user_id)
if payload.channel_id == Channel_ID and payload.message_id == Message_ID:
if str(payload.emoji) == "YourEmoji":
role = get(payload.member.guild.roles, name='RoleName') # Or id='RoleID'
else:
role = get(guild.roles, name=payload.emoji)
if role is not None:
await payload.member.add_roles(role) # Add the role
App Crashing with android material Chip Group with material 1.3.0
<com.google.android.material.chip.Chip
<!-- other props -->
android:theme="@style/Theme.MaterialComponents.Light />
-----------------------
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar.Bridge">
Populate V-Select from Json - Vue JS
computed: {
options() {
return Object.entries(this.serviceOptions)
.map(([key, value]) => ({text: key, value: value}));
},
},
-----------------------
data(){
return {
serviceOptions:{
"youtube":0,
"facebook":1,
....
}
}
},
computed: {
options() {
return Object.entries(this.serviceOptions)
.map(([key, value]) => ({text: key, value: value}));
},
},
<v-select v-model="serviceValues" :items="options" item-text="text" clearable multiple>
</v-select>
-----------------------
data(){
return {
serviceOptions:{
"youtube":0,
"facebook":1,
....
}
}
},
computed: {
options() {
return Object.entries(this.serviceOptions)
.map(([key, value]) => ({text: key, value: value}));
},
},
<v-select v-model="serviceValues" :items="options" item-text="text" clearable multiple>
</v-select>
how can I get the next question by clicking on button using jQuery
<script>
$(document).ready(function () {
$('#game,#movie,#sport,#genre,#action,#adventure,#scifi,#gta,#fpp,#historic,#indoor,#outdoor,#esport').hide();
$('#hobbie input').on('change',function () {
var x = $('#game,#movie,#sport,#genre,#action,#adventure,#scifi,#gta,#fpp,#historic,#indoor,#outdoor,#esport').hide();
})
$('#movie input').change(function () {
$('#game,#sport,#action,#adventure,#scifi,#gta,#fpp,#historic,#indoor,#outdoor,#esport').hide();
})
$('#game input').change(function () {
$('#movie,#sport,#genre,#action,#game#adventure,#scifi,#gta,#fpp,#historic,#indoor,#outdoor,#esport').hide();
})
$('#sport input').change(function () {
$('#game,#movie,#genre,#action,#adventure,#scifi,#gta,#fpp,#historic,#indoor,#outdoor,#esport').hide();
})
// for button position
jQuery.fn.center = function () {
this.css("position","absolute");
this.css("top", ( $(window).height() - this.height() ) / 1.2+$(window).scrollTop() + "px");
this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
return this;
}
$('#next').center();
$("#next").on('click', function(){
var hobbieselected = $('input[name=hobbie]:checked').val();
var movieselected = $('input[name=movie]:checked').val();
var gameselected = $('input[name=game]:checked').val();
var sportselected = $('input[name=sport]:checked').val();
if(hobbieselected == 'movie'){
$('#game,#sport,#gta,#fpp,#action,#adventure,#scifi#historic,#indoor,#outdoor,#esport').hide();
$('#movie').show();
}
else if(hobbieselected == 'game'){
$('#movie,#sport,#gta,#fpp,#action,#adventure,#scifi#historic,#indoor,#outdoor,#esport').hide();
$('#game').show();
}
else if(hobbieselected == 'sport'){
$('#movie,#game,#gta,#fpp,#action,#adventure,#scifi#historic,#indoor,#outdoor,#esport').hide();
$('#sport').show();
}
if(hobbieselected == 'movie' && movieselected == 'action'){
$('#game,#sport,#adventure,#scifi,#gta,#fpp,#historic,#indoor,#outdoor,#esport').hide();
$('#action').show();
}
else if(hobbieselected == 'movie' && movieselected == 'adventure'){
$('#sport,#action,#scifi,#gta,#fpp,#historic,#indoor,#outdoor,#esport').hide();
$('#adventure').show();
}
else if(hobbieselected == 'movie' && movieselected == 'scifi'){
$('#sport,#action,#adventure,#gta,#fpp,#historic,#indoor,#outdoor,#esport').hide();
$('#scifi').show();
}
if(hobbieselected == 'game' && gameselected == 'gta'){
$('#sport,#adventure,#scifi,#action,#fpp,#historic,#indoor,#outdoor,#esport').hide();
$('#gta').show();
}
else if(hobbieselected == 'game' && gameselected == 'fpp'){
$('#movie,#sport,#genre,#action,#game#adventure,#scifi,#gta,#historic,#indoor,#outdoor,#esport').hide();
$('#fpp').show();
}
else if(hobbieselected == 'game' && gameselected == 'historic'){
$('#movie,#sport,#genre,#action,#game#adventure,#scifi,#gta,#fpp,#indoor,#outdoor,#esport').hide();
$('#historic').show();
}
if(hobbieselected == 'sport' && sportselected == 'indoor'){
$('#game,#adventure,#scifi,#gta,#fpp,#historic,#action,#outdoor,#esport').hide();
$('#indoor').show();
}
else if(hobbieselected == 'sport' && sportselected == 'outdoor'){
$('#game,#movie,#genre,#action,#adventure,#scifi,#gta,#fpp,#historic,#indoor,#esport').hide();
$('#outdoor').show();
}
else if(hobbieselected == 'sport' && sportselected == 'esport'){
$('#game,#movie,#genre,#action,#adventure,#scifi,#gta,#fpp,#historic,#indoor,#outdoor').hide();
$('#esport').show();
}
});
});
</script>
How to get the Daily budget Consumed but not exceeding the total budget in SQL/BigQuery
select t.*,
greatest(least(total_budget - sum(least(click * cpc, daily_budget)) over (partition by app_pkg order by click),
least(click * cpc, daily_budget)
), 0
) as daily_rev
from t
order by click;
least(click * cpc, daily_budget)
-----------------------
select t.*,
greatest(least(total_budget - sum(least(click * cpc, daily_budget)) over (partition by app_pkg order by click),
least(click * cpc, daily_budget)
), 0
) as daily_rev
from t
order by click;
least(click * cpc, daily_budget)
-----------------------
#standardSQL
SELECT app_pkg, Click,
GREATEST(0,
LEAST(
total_budget - IFNULL(SUM(LEAST(click * cpc, daily_budget)) OVER(PARTITION BY app_pkg ORDER BY click ROWS BETWEEN UNBOUNDED PRECEDING AND 1 PRECEDING), 0),
LEAST(click * cpc, daily_budget)
)
) AS daily_rev
FROM `project.dataset.table`
-- ORDER BY click
Row app_pkg Click daily_rev
1 pubg 100 100
2 pubg 125 125
3 pubg 150 150
4 pubg 175 150
5 pubg 200 150
6 pubg 225 150
7 pubg 250 150
8 pubg 275 25
9 pubg 300 0
10 pubg 325 0
-----------------------
#standardSQL
SELECT app_pkg, Click,
GREATEST(0,
LEAST(
total_budget - IFNULL(SUM(LEAST(click * cpc, daily_budget)) OVER(PARTITION BY app_pkg ORDER BY click ROWS BETWEEN UNBOUNDED PRECEDING AND 1 PRECEDING), 0),
LEAST(click * cpc, daily_budget)
)
) AS daily_rev
FROM `project.dataset.table`
-- ORDER BY click
Row app_pkg Click daily_rev
1 pubg 100 100
2 pubg 125 125
3 pubg 150 150
4 pubg 175 150
5 pubg 200 150
6 pubg 225 150
7 pubg 250 150
8 pubg 275 25
9 pubg 300 0
10 pubg 325 0
LogStash Error: Can't get text on a START_OBJECT at 1:708
mutate {
rename => ["host", "hostname"]
convert => {"hostname" => "string"}
}
input {
beats {
port => "5044"
}
}
filter {
#If log line contains tab character followed by 'at' then we will tag that entry as stacktrace
if [message] =~ "\tat" {
grok {
match => ["message", "^(\tat)"]
add_tag => ["stacktrace"]
}
}
mutate {
rename => ["host", "hostname"]
convert => {"hostname" => "string"}
}
}
output {
stdout {
codec => rubydebug
}
# Sending properly parsed log events to elasticsearch
elasticsearch {
hosts => ["localhost:9200"]
}
}
-----------------------
mutate {
rename => ["host", "hostname"]
convert => {"hostname" => "string"}
}
input {
beats {
port => "5044"
}
}
filter {
#If log line contains tab character followed by 'at' then we will tag that entry as stacktrace
if [message] =~ "\tat" {
grok {
match => ["message", "^(\tat)"]
add_tag => ["stacktrace"]
}
}
mutate {
rename => ["host", "hostname"]
convert => {"hostname" => "string"}
}
}
output {
stdout {
codec => rubydebug
}
# Sending properly parsed log events to elasticsearch
elasticsearch {
hosts => ["localhost:9200"]
}
}
Can't print string from returned class
class match_start:
def choose_land(self):
print('You are in the plane. CHoose where to land')
land_area = input('->')
if land_area == 'bootcamp':
print('Bootcamp it is')
elif land_area == 'docks':
print('Docks it is')
else:
print('landed with bots')
class match_start:
def choose_land(self):
print('You are in the plane. CHoose where to land')
land_area = input('->')
destination = Destination(land_area)
destination.print_message()
class Destination(object):
def __init__(self, dest_name):
self.dest_name = dest_name
def print_message(self):
print (self.dest_name' + it is')
-----------------------
class match_start:
def choose_land(self):
print('You are in the plane. CHoose where to land')
land_area = input('->')
if land_area == 'bootcamp':
print('Bootcamp it is')
elif land_area == 'docks':
print('Docks it is')
else:
print('landed with bots')
class match_start:
def choose_land(self):
print('You are in the plane. CHoose where to land')
land_area = input('->')
destination = Destination(land_area)
destination.print_message()
class Destination(object):
def __init__(self, dest_name):
self.dest_name = dest_name
def print_message(self):
print (self.dest_name' + it is')
-----------------------
class LandArea:
def bootcamp(self):
print ('You are landed in Bootcamp!')
def docks(self):
print('You are landed in Docks!')
class Start_PubG(LandArea):
def choose_land(self):
print('You are in the plane. Choose where to land!')
land_area = input('->')
if land_area.lower() == 'bootcamp':
super().bootcamp()
elif land_area.lower() == 'docks':
super().docks()
else:
print('Landed with bots')
obj = Start_PubG()
obj.choose_land()
class Bootcamp:
def bootcamp(self):
print ('You are landed in Bootcamp!')
class Docks:
def docks(self):
print('You are landed in Docks!')
class Start_PubG(Bootcamp, Docks):
def choose_land(self):
print('You are in the plane. Choose where to land!')
land_area = input('->')
if land_area.lower() == 'bootcamp':
super().bootcamp()
elif land_area.lower() == 'docks':
super().docks()
else:
print('Landed with bots')
obj = Start_PubG()
obj.choose_land()
class Bootcamp:
def bootcamp(self):
print ('You are landed in Bootcamp!')
class Docks:
def docks(self):
print('You are landed in Docks!')
class Start_PubG(Bootcamp, Docks):
def choose_land(self):
print('You are in the plane. Choose where to land!')
land_area = input('->')
if land_area == 'Bootcamp':
obj_ref = eval(land_area)
obj_ref().bootcamp()
elif land_area == 'Docks':
obj_ref = eval(land_area)
obj_ref().docks()
else:
print('Landed with bots')
obj = Start_PubG()
obj.choose_land()
-----------------------
class LandArea:
def bootcamp(self):
print ('You are landed in Bootcamp!')
def docks(self):
print('You are landed in Docks!')
class Start_PubG(LandArea):
def choose_land(self):
print('You are in the plane. Choose where to land!')
land_area = input('->')
if land_area.lower() == 'bootcamp':
super().bootcamp()
elif land_area.lower() == 'docks':
super().docks()
else:
print('Landed with bots')
obj = Start_PubG()
obj.choose_land()
class Bootcamp:
def bootcamp(self):
print ('You are landed in Bootcamp!')
class Docks:
def docks(self):
print('You are landed in Docks!')
class Start_PubG(Bootcamp, Docks):
def choose_land(self):
print('You are in the plane. Choose where to land!')
land_area = input('->')
if land_area.lower() == 'bootcamp':
super().bootcamp()
elif land_area.lower() == 'docks':
super().docks()
else:
print('Landed with bots')
obj = Start_PubG()
obj.choose_land()
class Bootcamp:
def bootcamp(self):
print ('You are landed in Bootcamp!')
class Docks:
def docks(self):
print('You are landed in Docks!')
class Start_PubG(Bootcamp, Docks):
def choose_land(self):
print('You are in the plane. Choose where to land!')
land_area = input('->')
if land_area == 'Bootcamp':
obj_ref = eval(land_area)
obj_ref().bootcamp()
elif land_area == 'Docks':
obj_ref = eval(land_area)
obj_ref().docks()
else:
print('Landed with bots')
obj = Start_PubG()
obj.choose_land()
-----------------------
class LandArea:
def bootcamp(self):
print ('You are landed in Bootcamp!')
def docks(self):
print('You are landed in Docks!')
class Start_PubG(LandArea):
def choose_land(self):
print('You are in the plane. Choose where to land!')
land_area = input('->')
if land_area.lower() == 'bootcamp':
super().bootcamp()
elif land_area.lower() == 'docks':
super().docks()
else:
print('Landed with bots')
obj = Start_PubG()
obj.choose_land()
class Bootcamp:
def bootcamp(self):
print ('You are landed in Bootcamp!')
class Docks:
def docks(self):
print('You are landed in Docks!')
class Start_PubG(Bootcamp, Docks):
def choose_land(self):
print('You are in the plane. Choose where to land!')
land_area = input('->')
if land_area.lower() == 'bootcamp':
super().bootcamp()
elif land_area.lower() == 'docks':
super().docks()
else:
print('Landed with bots')
obj = Start_PubG()
obj.choose_land()
class Bootcamp:
def bootcamp(self):
print ('You are landed in Bootcamp!')
class Docks:
def docks(self):
print('You are landed in Docks!')
class Start_PubG(Bootcamp, Docks):
def choose_land(self):
print('You are in the plane. Choose where to land!')
land_area = input('->')
if land_area == 'Bootcamp':
obj_ref = eval(land_area)
obj_ref().bootcamp()
elif land_area == 'Docks':
obj_ref = eval(land_area)
obj_ref().docks()
else:
print('Landed with bots')
obj = Start_PubG()
obj.choose_land()
QUESTION
How to store dictionary inside defaultdict(list)
Asked 2021-May-28 at 18:47import pandas as pd
import re
from collections import defaultdict
d = defaultdict(list)
df = pd.read_csv('https://raw.githubusercontent.com/twittergithub/hello/main/category_app_id_text_1_month_march_2021%20(1).csv')
and the output for the dataframe is ..
suggestions category
0 ['jio tv', 'jio', 'jiosaavn', 'jiomart', 'jio ... ['BOOKS_AND_REFERENCE',
'PRODUCTIVITY', 'MUSIC...
1 ['instagram', 'internet', 'instacart', 'instag... ['SOCIAL', 'COMMUNICATION',
'FOOD_AND_DRINK', ...
2 ['instagram', 'instacart', 'instagram download... ['SOCIAL', 'FOOD_AND_DRINK',
'VIDEO_PLAYERS', ...
3 ['vpn', 'vpn free', 'vpn master', 'vpn private... ['TOOLS', 'TOOLS', 'TOOLS', 'TOOLS',
'TOOLS', ...
4 ['pubg', 'pubg mobile lite', 'pubg lite', 'pub... ['GAME_ACTION', 'GAME_ACTION',
'TOOLS', 'GAME_...
... ...
...
49610 ['inbuilt camera app', 'inbuilt screen recorde... ['PHOTOGRAPHY', 'VIDEO_PLAYERS',
'TOOLS', 'PRO...
49611 ['mpsc science app in marathi', 'mpsc science ... ['EDUCATION', 'EDUCATION',
'EDUCATION', 'EDUCA...
49612 ['ryerson', 'ryerson university', 'ryerson mob... ['BOOKS_AND_REFERENCE', 'EDUCATION',
'EDUCATIO...
49613 ['eeze', 'eezee english', 'ezee tab', 'deezer'... ['TRAVEL_AND_LOCAL', 'EDUCATION',
'BUSINESS', ...
49614 ['hindi love story books free download', 'hind... ['BOOKS_AND_REFERENCE',
'BOOKS_AND_REFERENCE',...
If want to create a dictionary of category columns for each item present in the list of category in each row and inside each category create a dictionary of suggestions from suggestions columns and if suggestions or categories are repeating, then just increment the counter inside the dictionary.
dictionary = defaultdict(list)
for i in range(df.shape[0]):
categories = set(re.sub(r'[^\w\s]', '', df.loc[i, 'category']).split())
for category in categories:
suggestions = set(re.sub(r'[^\w\s]', '', df.loc[i, 'suggestions']).split())
for suggestion in suggestions:
if suggestion not in dictionary[category]:
dictionary[category][suggestion] = 1
else:
dictionary[category][suggestion] += 1
but I am getting empty list inside list of category inside defaultdict. I hope that you understand my question.
ANSWER
Answered 2021-May-28 at 18:47It's probably a bit easier and faster to do with pandas
:
from ast import literal_eval
# create cartesian product of categories and suggestions for each record,
# and calculate value_counts
z = pd.merge(
df['category'].apply(literal_eval).explode(),
df['suggestions'].apply(literal_eval).explode(),
left_index=True,
right_index=True).value_counts()
# convert to nested dict
d = {l: z.xs(l).to_dict() for l in z.index.levels[0]}
d
Output:
{'ART_AND_DESIGN': {'flipaclip': 39,
'mehndi design': 28,
'ibis paint x': 22,
'u launcher lite': 21,
'poster maker': 20,
'poster maker design app free': 20,
'ibis paint': 18,
'mehndi design 2021': 18,
'mehandi ka design': 18,
'u launcher': 18,
...
Having said this, if you want to go with the original approach, all you need to fix is to declare the dictionary
as defaultdict(dict)
instead of defaultdict(list)
, because you're making a nested dictionary, not a dictionary of lists:
dictionary = defaultdict(dict)
for i in range(df.shape[0]):
...
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
No vulnerabilities reported
Save this library and start creating your kit
Save this library and start creating your kit