« first day (13 days earlier)      last day (107 days later) » 

10:16 AM
@TheGreat
 
hi
Any idea what's the issue with my approach?
 
Hello :)
just a min let me check your solution.
 
btw, thanks for your help as usual
 
Can you format the code? Just press CTRL + K
 
Which code? I deleted the code I pasted here
 
10:24 AM
Ok no worries.
 
col = df.columns.str
c1 = col.endswith('id')
c2 = col.contains('value')
c3 = col.contains('datetime')
missing_value_filled = np.select([c1,c2,c3],[df.fillna(0),df.fillna(np.nan),df.fillna("01/01/2000 00:00:00")])
pd.DataFrame(missing_value_filled, columns=df.columns)
I pasted my code here
 
I think you are misinterpreting the use of np.select.
Let me explain with example:
Consider the df:
np.random.seed(1)
df = pd.DataFrame(np.random.randint(0, 100, 25).reshape(-1, 5))

    0   1   2   3   4
0  37  12  72   9  75
1   5  79  64  16   1
2  76  71   6  25  50
3  20  18  84  11  28
4  29  14  50  68  87
 
okay
 
Consider the boolean masks:
m1 = df < 10
m2 = df > 25

>>> m1
       0      1      2      3      4
0  False  False  False   True  False
1   True  False  False  False   True
2  False  False   True  False  False
3  False  False  False  False  False
4  False  False  False  False  False

>>> m2
       0      1      2      3      4
0   True  False   True  False   True
1  False   True   True  False  False
2   True   True  False  False   True
3  False  False   True  False   True
4   True  False   True   True   True
Now lets say we want to replace all the values less that 10 with 'A and all the values greater than 25 with B
We can use np.select in such case as follows:
df[:] = np.select([m1, m2], ['A', 'B'], default=df)
>>> df

    0   1  2   3  4
0   B  12  B   A  B
1   A   B  B  16  A
2   B   B  A  25  B
3  20  18  B  11  B
4   B  14  B   B  B
 
Wow.. Let me read this line by line to understand the code. Thanks a lot for your help
will update you soon..
Thanks for your time and help...
Will come back here for any questions
Okay with you/
 
10:39 AM
Sure! More than happy to help :)
np.select requires boolean masks of equal shape for proper alignment of values and values must be broadcastable to the shape of boolean masks.
Its just like:
if <some_cond>:
    pass
elif <some_other_cond>:
    pass
else:
    pass
 
10:56 AM
Here is one more example:
Let's say we want to multiply all the values less than 10 with 2 and all the values greater than 10 with 3, we could use np.select as follows:
df[:] = np.select([m1, m2], [df.mul(2), df.mul(3)], default=df)
>>> df
     0    1    2    3    4
0  111   12  216   18  225
1   10  237  192   16    2
2  228  213   12   25  150
3   20   18  252   11   84
4   87   14  150  204  261
Notice here df.mul(2) and df.mul(3) are of same shape as m1 and m2
 
Thanks a lot for your help. YOu have been so kind
 
Glad i could help :)
 
 
1 hour later…
12:24 PM
Hi Shubham, I tried to implement it, but it did not work. The right df remains the same?
 
12:48 PM
Hi @Christopher
Can you share the link for the question?
 
 
4 hours later…
4:56 PM
@Christopher lets discuss hereShubham Sharma yesterday
So here's the thing: Over the next few weeks, I need to match every week each two participants in a program. I have one long list of subscriptions. But the matches may not repeat, and it can happen that new entries are added to the list. am not sure yet how to solve this..
@Christopher lets discuss hereShubham Sharma yesterday
 
5:47 PM
@Christopher
 

« first day (13 days earlier)      last day (107 days later) »