All Questions
Tagged with python-itertools dataframe
53 questions
2
votes
1
answer
56
views
itertools.product in dataframe
Inputs:
arr1 = ["A","B"]
arr2 = [[1,2],[3,4,5]]
Expected output:
short_list
long_list
0
A
1
1
A
2
2
B
3
3
B
4
4
B
5
Current output:
short_list
long_list
0
A
[1, 2]
1
A
[3, 4, 5]...
1
vote
1
answer
60
views
Optimizing DataFrame Processing for User Login Intervals with Pandas
I'm working on a function that processes the login times of users on a website. These times are stored in a Pandas DataFrame where the first column indicates a time interval, and the rest indicate if ...
0
votes
0
answers
43
views
Memory Error - itertools.product between pd.groupby() groups without using lists
I'm trying to itertools.product multiple very large DataFrames and perform simple math on each combination to filter out unwanted combinations.
The problem is that translating the results from list(...
1
vote
1
answer
56
views
python - pandas: function to replicate the creation of a variable
I am trying to replicate the variable aux_35, because I have some missing values in my database. Here is a little sample of the dataset:
import pandas as pd
import numpy as np
import matplotlib....
0
votes
2
answers
105
views
Python : Replace two for loops with the fastest way to sum the elements
I have list of 5 elements which could be 50000, now I want to sum all the combinations from the same list and create a dataframe from the results, so I am writing following code,
x =list(range(1,5))
t=...
0
votes
0
answers
83
views
How do I use itertools for these nested for loops
I have a dataframe I want to iterate through using a function, but can't seem to use itertools correctly. The below nested for loop works fine!
columns = len(df_test.columns)
rows = len(df_test.index)
...
1
vote
1
answer
182
views
how to transform a itertools.permutations to a dataframe in ptyhon?
I need to change a itertools.permutations into a format that i can use, such a dataframe or list, is possible to create a dataframe with itertools.permutations
how to transform a itertools....
0
votes
1
answer
78
views
Find groups with not not a number
I have a dataframe containing some coded answers to a questionnaire.
Each row is a respondent and each column is a question. Not every person responded to the same questions because of some skip logic ...
1
vote
2
answers
325
views
Convert a list to dataframe using for loop
from itertools import chain
data_c = chain(data[0].values,
data[1].values,
data[2].values,
data[3].values,
data[4].values,
data[5].values,
data[6].values)
headers=chain(data[0])
df = pd.DataFrame(...
0
votes
1
answer
37
views
Create data frames for each unique permutation of groups of a Dataframe
Suppose I have the following Dataframe in Python:
input_df = pd.DataFrame({
'Previous': ['1000', '1000', 'latex', 'latex'],
'Ignore':[None, None, ['free'], ['free']],
'New': ['100', ...
2
votes
1
answer
363
views
How to do I count the number of string combinations in each row of a pandas dataframe?
I'm trying to count the number of times a combination of strings appear in each row of a dataframe. Each ID uses a number of methods (some IDs use more methods than others) and I want to count the ...
2
votes
2
answers
425
views
Generate all multiplicative (product) combinations of columns in a pandas dataframe
I would like to generate all 2-way (and possibly 3-way) "multiplicative" combinations (i.e., column1 x column2, column2 x column3, column1 x column3, column1 x column 2 x column3, etc) of a ...
1
vote
1
answer
134
views
Python Pandas Concatenate Combinations All Columns Dynamically
COL_A
COL_B
COL_C
PRODUCT_1
UK
1/1/2021
I want to have a table that contains the result
COL_A
COL_B
COL_C
COL_A_COL_B_COL_C
COL_A_COL_B
COL_A_COL_C
COL_B_COL_C
PRODUCT_1
UK
1/1/2021
PRODUCT_1UK1/1/...
0
votes
1
answer
3k
views
How to use multiprocessing pool.starmap with multiple arguments
I have a question.. for using Pool.starmap..
p1 = pd.dataframe(example1)
p2 = pd.dataframe(example2)
pairs = itertools.product(p1.iterrows(), p2.iterrows())
pairs_len = len(p1) * len(p2)
tpairs = ...
0
votes
1
answer
97
views
Using a column of values to create a counter for a variable sequential number column
I currently have a pandas dataframe with some columns. I'm looking to build a column, Sequential, that lists what iteration is recorded at that part of the cycle. I'm currently doing this using ...