Search code examples
pythonpandasalpha-vantage

How do I reverse a CSV- Python


I'm trying to create a stock market predicting algorithm and I'm using alpha vantage as my api for stock prices. However, they store their data from newest to oldest. Is there any way to change this from oldest to newest?

ts = TimeSeries(key=api_key, output_format='pandas')
data, meta_data = ts.get_daily(self.symbol, outputsize='full')
data.to_csv(f'./{self.symbol}_daily.csv')
print(data)

Edit: The CSV is a Data Frame with the following columns: Index (0-2599), Date, Open, High, Low, Close


Solution

  • Yes, you can quickly reformat your data with:

    data = data.iloc[::-1]
    

    I would recommend reviewing pandas indexing closely from here.