I have a Dataframe, and one column is full of lists of words. I am using a function to remove all words that are not in a secondary list. When I use apply to trim my lists I get a warning telling me I should use .loc but I'm not sure how to use it properly with apply.
here is my function
def trimTo20(tweet):
for check in reversed(tweet):
if check not in over20Hash:
tweet.remove(check)
return(tweet)
here is my call
group20.sumText = group20.sumText.apply(trimTo20)
and here is the warning.
Anaconda3\lib\site-packages\pandas\core\generic.py:3110:
SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: http://pandas.pydata.org/pandas-
docs/stable/indexing.html#indexing-view-versus-copy
self[name] = value
and here is a slice of my Dataframe
UserID sumText
3 1644 [#life, #contentmarketing, #ContentMarketing]
5 1737 [@SwiftOnSecurity, @erinscafe, @ComfortablySmug]
8 2391 [@, @MikeIsaac, @fmanjoo, @rtraister, @TheCut, @twitter]
10 2426 [@MikeIsaac, @GOP, @united, @facebook, @gruber]
everything appears fine in my dataframe, should I be concerned that some data didn't copy over correctly? I've used apply a couple times this way and never gotten this warning.