Python

Room rules: sopython.com/chatroom Code formatting guide: tinyu...
Jun 17, 2021 16:42
@roganjosh Yea, the link is even more a red flag, because it's a custom link tailored to identify traffic coming from stack overflow, so even more of a marketing campaign.
Jun 17, 2021 16:38
Yea, I flagged a few then realized it was every one of their answers, will just leave one, thanks for the input.
Jun 17, 2021 16:36
If it was just one answer I'd probably just edit + leave a comment, but it's around 30, all with the same advertisement at the end.
Jun 17, 2021 16:35
Hey all, moderation question. Came across this answer: stackoverflow.com/a/68023134/3483203, and noticed that every answer by the user advertises their commercial product, regardless of it usually being irrelevant to the question. Should I just be flagging them all for spam, or if I just left a note on one for moderator attention would they check their other posts?
Jan 27, 2020 17:16
I usually end up writing my own expanding methods, but if you want more predictable behavior you probably won't do too much better than df.apply(lambda x: x.expanding().mean(), axis=1)
Jan 27, 2020 17:14
No, not at all. It's more useful on series, not dataframes.
Jan 27, 2020 17:12
You'll also notice that it's not on a per-row basis, it's per column.
Jan 27, 2020 17:11
And yes, expanding and rolling are notoriously poorly documented.
Jan 27, 2020 17:11
The nan is canceling out your window and starts a new window at 7. Try adding another non-nan column and you'll see the behavior.
Jan 27, 2020 16:20
The example you gave of sum does in fact ignore nans
Jan 27, 2020 16:17
While the expanding window itself doesn't have an option to skipna, most of the functions you can call on a window do. If the function you need doesn't, you can just write your own that does. The expanding operations aren't particularly efficient.
Aug 10, 2019 21:25
Ah I guess I wasn't clear. I don't want to have to explicitly define that class for every dictionary, I want to have something that turns many dictionaries into many classes. That's the purpose of _wraps_class
Aug 10, 2019 21:05
@Peilonrayz it work fine, just feels like there should be a better way
Aug 10, 2019 20:53
    def get():
        return 'You got got'

    d = {'get': get}


# I basically want to go from ^ that dictionary to the following class

    class Dynamic(ParentClass):
        @staticmethod
        def get():
            return 'You got got'

# The only way I can get to work currently is a pretty hacky wrapper function.  Am I missing something obvious?

    def _wraps_class(methods):
        class Dynamic(ParentClass):
            pass

        for method, method_fn in methods.items():
            setattr(Dynamic, method, staticmethod(method_fn))
Aug 10, 2019 20:53
It might be a bit long for chat, if it is I'll delete and post on main
Aug 10, 2019 20:53
Have a question that's been kicking my behind today.
Aug 10, 2019 20:50
cabbage
Aug 6, 2019 14:30
ty
Aug 6, 2019 14:29
that one, not the other
Aug 5, 2019 17:21
But that doesn't answer your question as to how to make your code run more efficiently, can you PM me the head of each of your DataFrames?
Aug 5, 2019 17:20
This is all clearly defined in the documentation, and it covers the dangers of chained indexing
 
Aug 5, 2019 17:44
happy to help
Aug 5, 2019 17:42
If you pass a list instead of a label, it will return a DataFrame, not a Series
Aug 5, 2019 17:41
labels.loc[labels['url'] == i, 'category']
Aug 5, 2019 17:37
Correct
Aug 5, 2019 17:36
InvalidIndexError: Reindexing only valid with uniquely valued Index objects
Aug 5, 2019 17:36
It would let you set the index, but the map would fail.
Aug 5, 2019 17:34
That solve your issue?
Aug 5, 2019 17:33
When compared to df2
Aug 5, 2019 17:33
Missing values will be NaN and will evaluate as False
Aug 5, 2019 17:32
This assumes that url is unique in df1
Aug 5, 2019 17:32
0     True
1     True
2    False
dtype: bool
Aug 5, 2019 17:32
df2.url.map(m) == df2.category
Aug 5, 2019 17:32
Then you just need:
Aug 5, 2019 17:31
m = df1.set_index('url')['category']
Aug 5, 2019 17:31
That's fine, make df1 a mapping series with url as index, so:
Aug 5, 2019 17:30
You would want True True False correct?
Aug 5, 2019 17:30
   turk         url category
0     1  google.com        G
1     2   yahoo.com        S
2     3  google.com        S
Aug 5, 2019 17:30
And this is df2
Aug 5, 2019 17:29
          url category
0  google.com        G
1   yahoo.com        S
Aug 5, 2019 17:29
So let's say this is df1:
Aug 5, 2019 17:29
You don't need a loop
Aug 5, 2019 17:26
So can you explain your output? Should it look up the url in gold and make sure that category equals the category in gold?
Aug 5, 2019 17:24
There ya go
Aug 5, 2019 17:24
```
Aug 5, 2019 17:24
Put it between ``` ```
Aug 5, 2019 17:23
I would format that as code so you aren't linking to pornographic websites