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.