0

I have a list called testList that contains a couple of timeseries that I am trying to convert its values from string to float. The list is very long and part of it looks like:

testList [date
2015-02-09    5083.628505
2015-02-10    5588.064283
2015-02-12    5716.556323
2015-02-13    5687.040303
2015-02-16    5746.323570
                 ...
2016-02-29    7460.167850
2016-03-01    7520.165439
2016-03-02    7710.032381
2016-03-03    7730.081164
2016-03-04    8040.123012
Name: adjusted_snap, Length: 263, dtype: float64, date
2015-02-09    5107.125395
2015-02-10    5579.177926
2015-02-12    5721.690076
2015-02-13    5690.344229
2015-02-16    5779.747352
                 ...
2016-02-29    7454.380019
2016-03-01    7505.175458
2016-03-02    7729.729257
2016-03-03    7764.529861
2016-03-04    8060.349081
Name: adjusted_vwap, Length: 263, dtype: float64]

For information the type is <class 'list'>.

All the values are numbers (except where there is a missing value and its null).

I am trying to convert the list values from string to float using:

for item in testList:
            for key, value in item.iteritems():
                try:
                    item[key] = float(value)
                except ValueError:
                    continue

However I get a SettingWithCopyWarning.

     SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  item[key] = float(value)

I am very confused as I am using a list but the warning mentions a dataframe. I have had a good look for solution and there is a lot of information but I can't find a fix to my copy warning problem.

halfer
  • 19,824
  • 17
  • 99
  • 186
Stacey
  • 4,825
  • 17
  • 58
  • 99
  • It looks like you are working with `pandas dataframe`. – ywbaek Mar 24 '20 at 19:53
  • Hi Stacey. Quick reminder: there is no need to add chatty material into your posts, as per prior edits to your material. "Please help me" pleading or other forms of claimed helplessness is not liable to get you faster attention. Readers will know to ask for new information, so offering "additional information as needed" is again redundant. – halfer Mar 24 '20 at 20:51
  • I sometimes offer the following advice: _Note that we prefer a technical style of writing here. We gently discourage greetings, hope-you-can-helps, thanks, advance thanks, notes of appreciation, regards, kind regards, signatures, please-can-you-helps, chatty material and abbreviated txtspk, pleading, how long you've been stuck, voting advice, meta commentary, etc. Just explain your problem, and show what you've tried, what you expected, and what actually happened._ – halfer Mar 24 '20 at 20:52
  • Where you have information in angle brackets, like ``, you need to use inline code formatting, otherwise it will be treated as invalid HTML, and ignored by the Stack Overflow page renderer. Please use the preview window prior to submitting. – halfer Mar 24 '20 at 20:53
  • Does this answer your question? [How to deal with SettingWithCopyWarning in Pandas?](https://stackoverflow.com/questions/20625582/how-to-deal-with-settingwithcopywarning-in-pandas) – AMC Apr 24 '20 at 00:23

0 Answers0