How do I replace set_value with at[] in a pandas Series
Replace strikes.set_value(i, strike)
with strikes.at[i] = strike
.
Note that assignment back to a series is not necessary with set_value
:
s = pd.Series()
s.set_value(0, 10)
s.at[1] = 20
print(s)
0 10
1 20
dtype: int64
For the algorithm you are looking to run, you can simply use assignment:
strikes = rawData['Symbol'].str[-6:].astype(float) / 1000
user1067305
I started programming in 1964, with Fortran. I've programmed extensively in Fortran, 360 Assembler, PL/I, and especially C. I've also dabbled in Forth, APL, Prolog, Basic, & Java. Most recently I've been using javascript and perl. I'm new to python.
Updated on June 04, 2022Comments
-
user1067305 almost 2 years
I'm trying to construct a pandas Series to concatenate onto a dataframe.
import numpy as np import pandas as pd rawData = pd.read_csv(input, header=1) # the DataFrame strikes = pd.Series() # the empty Series for i, row in rawData.iterrows(): sym = rawData.loc[i,'Symbol'] strike = float(sym[-6:])/1000 strikes = strikes.set_value(i, strike) print("at26: ",strikes.values)
This program works, but I get the error message:
"line 25: FutureWarning: set_value is deprecated and will be removed in a future release. Please use .at[] or .iat[] accessors instead."
Every way I have tried to substitute .at, I get a syntax error. Many of the suggestions posted relate to DataFrames, not Series. Append requires another series, and complains when I give it a scalar.
What is the proper way to do it?
-
user1067305 over 5 yearsRight on both counts! Thank you.