tuples

Python: Loop through tuple and insert into Data Frame for each value

Python: Loop through tuple and insert into Data Frame for each value Question: Trying to loop through the tuple that is currently a column in my data frame. For the first ID I want to select the first item in the group tuple then for the second ID select the second variable in the tuple. …

Total answers: 3

Find tuples in a list of tuples, with consecutive values and turn them into bigger tuples

Find tuples in a list of tuples, with consecutive values and turn them into bigger tuples Question: I have a list of tuples, each having two elements. Example: my_tuples = [(‘black’, ‘grey’), (‘red’, ‘orange’), (‘blue’, ‘purple’), (‘orange’, ‘yellow’), (‘grey’, ‘white’), (‘yellow’, ‘cream’)] I am looking for an efficient way to find all the tuples whose …

Total answers: 2

Grouping Python dict by 2nd item in key tuple

Grouping Python dictionary by 2nd item in key tuple Question: I have a dictionary: {(bob, CA): 90, (tom, NJ): 80, (sarah, CA): 90, (jon, TX): 90} I would like to group by the 2nd item in the key tuple: {CA: {bob: 90, sarah: 90}, NJ: {tom: 80}, TX: {jon: 90}} I could formulate this by …

Total answers: 2

how can i solve error ''float' object is not iterable'

how can i solve error ''float' object is not iterable' Question: im new at python, and try to categorize places an df1 by distance to places in df2, but something gonna wrong i have 2 dataframes whith coordinate of places import pandas as pd import geopy.distance df1 = pd.DataFrame([[‘a’, 55.88, 37.48], [‘b’, 55.88, 37.53], [‘c’, …

Total answers: 2

Python How To Assign 2 Variables in One Part(?)

Python How To Assign 2 Variables in One Part(?) Question: Im sorry ı couldn’t write decent title. But let me explain. a list that holds ten variable list[0] = tshirt but if user search t-shirt in that list, program should accept it as tshirt. What Im asking is, can I say list[0] = "tshirt" or …

Total answers: 3

Make tuple of sets in Python

Make tuple of sets in Python Question: I want to put two sets in a tuple in Python. set1 = set(1, 2, 3, 4) set2 = set(5, 6, 7) What I’ve tried: result = tuple(set1, set2) # got error "TypeError: tuple expected at most 1 argument, got 2" Desired output: ({1, 2, 3, 4}, {5, …

Total answers: 2

Delete all tuples from a list, if the first two elements of another tuple matches

Delete all tuples from a list, if the first two elements of another tuple matches Question: i have two tuple lists, and i want to delete all tuples from list1, if the first two elements of a tuple from list2 matches with the first two elements of a tuple from list1. list1 = [(‘google’, ‘data’, …

Total answers: 2

why i cannot pass a tuple to a function (which adress is reference in a dict), i have a error message (missing 1 required positionnal agrument)

why i cannot pass a tuple to a function (which adress is reference in a dict), i have a error message (missing 1 required positionnal agrument) Question: i have the below code : (df_data is a dataframe in this code) def instr_date(df_data,num): return df_data.index[-num] dict_func = {‘instr_date’ : instr_date,} dict_arg = {‘instr_date’ : (df_data_instr,),} dict_col_func …

Total answers: 1