Variable number of nested for loops in Python

I am having trouble getting this to work and any help would be greatly appreciated. I want to have a variable number of nested for loops for the following code. The idea is to write every combination possible to a csv file. here is my code: ` ka = [0.217, 0.445] kb = [0.03, 0.05]… Read More Variable number of nested for loops in Python

How to replace the values of nested lists stored in python dataframe?

I have the following dataframe data = [[[[[1, 2, 0], [1]],[[1, 2], [4]]], [[[[1, 2], [4]]]], [[[1]]]], [[[[1, 2, 0], [1]],[[1, 2], [4]]], [[[[1, 2], [4]]]], [[[1]]]]] df = pd.DataFrame(data) Also, I have a second dataframe df2: data2 = [[1, 10], [1, 15], [1, 14], [1, 20], [1, 18]] df2 = pd.DataFrame(data2, columns=[‘dir’, ‘line’]) The… Read More How to replace the values of nested lists stored in python dataframe?

How to Write a Nested For Loop in One Line Python with File Url and File Name

data = json.dumps({‘conf’:{a:b for a in table_name for b in file_url}}) print(data) I have 2 files in file_url. sales_dy_20221022.csv sales_wk_20221022 I have 2 table names in table_name sales_dy sales_wk If I write the code like the above I get the result below. "conf": { "sales_dy": "sales_dy_20221022.csv", "sales_wk": "sales_dy_20221022.csv" } How can I change the code… Read More How to Write a Nested For Loop in One Line Python with File Url and File Name

Create a pandas dataframe from a nested json file

I have the following json file: { "data": { "start_date": "2022-10-01", "end_date": "2022-10-04", "cur": "EUR", "prizes": { "2022-10-01": { "coffee": 0.1448939471560284, "usd": 1 }, "2022-10-02": { "coffee": 0.14487923291390148, "usd":1 }, "2022-10-03": { "coffee": 0.1454857922753868, "usd": 1 } } } } I want to create a dataframe which looks like this, (so without the usd column):… Read More Create a pandas dataframe from a nested json file

How can i calculate the sum of numbers in a nested dict. in python

How can i calculate the sum or total points of numbers of this nested dict. in python i tried alot of things and it didn’t work all time get the last value in the loop not every grade or value. ……………………………………………………………………………………………………………………………………………………………………………………………………………………………………………… # Input students = { "Ahmed": { "Math": "A", "Science": "D", "Draw": "B", "Sports":… Read More How can i calculate the sum of numbers in a nested dict. in python

How to obtain the values of provided data in which a minimum value occurs in a list?

So I’ve been trying to select 2 parameters as a result in which the minimum value occurs in another calculation (the error below). Consider the following dummy code for better understanding: def min_error(par1, par2): output = {"parameters": {"par1": [], "par2": []}, "error": [] } for i in par1: for j in par2: reg = somefunction(par1… Read More How to obtain the values of provided data in which a minimum value occurs in a list?

Create many new column df, having a nested column inside that df

I have a data frame that looks like this: a = {‘price’: [1, 2], ‘nested_column’: [[{‘key’: ‘code’, ‘value’: ‘A’, ‘label’: ‘rif1’}, {‘key’: ‘datemod’, ‘value’: ’31/09/2022′, ‘label’: ‘mod’}], [{‘key’: ‘code’, ‘value’: ‘B’, ‘label’: ‘rif2’}, {‘key’: ‘datemod’, ‘value’: ’31/08/2022′, ‘label’: ‘mod’}]]} df = pd.DataFrame(data=a) My expected output should look like this: b = {‘price’: [1, 2], ‘code’:["A","B"],… Read More Create many new column df, having a nested column inside that df