Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to select specific columns for Matrix in python

Tags:

python

I was doing the PCA stuff, and there are 8 columns that are [ "Price", "Earnings/Share", "Book Value", "52 week low", "52 week high", "Market Cap", "EBITDA", "Price/Sales".]

sp_data = pd.DataFrame(scale(SP.iloc[:, 3:11]), index=SP.Symbol, columns=SP.columns[3:11])

this is the code that to pick out all columns in the first row, and I only want to pick out the "price", "earnings/share", "market cap", and "EBITDA", what shoud I enter in the [], or some other way to let it work, please give me some hit, thank you so much

like image 803
Bai Avatar asked Mar 23 '26 02:03

Bai


1 Answers

Use:

new_df = df[['price', 'earnings/share', 'market cap', 'EBITDA']]

Although, I am sure this is a duplicate question.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!