Reputation: 1
I want only the date shows yyy-mm-dd, not as in the pictures, I'm learning python and actually I do not know how to do that, thanks for your help
import yfinance as yf
tesla = yf.Ticker('TSLA')
tesla = pd.DataFrame(tesla.history(perido='1d'))
tesla = tesla[['Close', 'Open', 'High', 'Low']]
print(tesla)
Upvotes: 0
Views: 2109
Reputation:
If you are retrieving the open, high, low, close, and adj close price. You can actually just use yf.download
.
df = yf.download('TSLA',start='2022-10-10',end='2022-10-11')
[*********************100%***********************] 1 of 1 completed
Open High ... Adj Close Volume
Date ...
2022-10-10 223.929993 226.990005 ... 222.960007 67715000
[1 rows x 6 columns]
df[['Close','Open','High','Low']]
Close Open High Low
Date
2022-10-10 222.960007 223.929993 226.990005 218.360001
To remove the time from the date, you can use dt.normalize
when your column is already a datetime.
df.reset_index(inplace=True)
df['Date'] = df['Date'].dt.normalize()
df.set_index('Date', inplace=True)
Upvotes: 1