I have data as follows in a DataFrame
symbolData
:
Open High Low Close Volume Ex-Dividend Split Ratio Adj. Open Adj. High Adj. Low Adj. Close Adj. Volume
Date
1980-12-12 28.75 28.8700 28.7500 28.75 2093900.0 0.0 1.0 0.424421 0.426193 0.424421 0.424421 117258400.0
When I get just the series
with the Adj Close
column, I would like to give it a name:
adjClose = symbolData.ix[:,10]
Right now, the above looks like
Date
1980-12-12 0.424421
I would like it to look like
AlgoClose
Date
1980-12-12 0.424421
rename() function is used to alter Series index labels or name for the given Series object. inplace : Whether to return a new Series. If True then value of copy is ignored. level : In case of a MultiIndex, only rename labels in the specified level.
Method 1: Using rename() function One way of renaming the columns in a Pandas Dataframe is by using the rename() function. This method is quite useful when we need to rename some selected columns because we need to specify information only for the columns which are to be renamed.
Pandas Series: rename() functionThe rename() function is used to alter Series index labels or name.
You can rename the Series and then use .to_frame to convert it to a dataframe. Also, it's better to use iloc instead of ix as it's going to be deprecated in the future.
df.iloc[:,10].rename('AlgoClose').to_frame()
Out[20]:
AlgoClose
Date
1980-12-12 0.424421
This will do the job:
adjClose = symbolData.ix[:,10].rename("AlgoClose")
adjClose =pd.DataFrame(adjClose)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With