How can I sort the float list

Samar Pratap Singh

I was writing this code for downloading the stock data and finding the percentage change in the price over the given time span. After doing all the calculations, retrievals, and storing the final data in a list, I wanted to sort the change list, but I was unable to do so. Please help me!

from pandas_datareader import data
import matplotlib.pyplot as plt
import pandas as pd
from datetime import date
import numpy as np

change=[]
today = date.today()
tickers = ['^GSPC', 'AAPL', 'MSFT', 'GOOG', 'MS', 'JPM']
for tick in tickers:
  start_date = '2012-01-01'
  end_date = today
  dataset = data.DataReader(tickers, 'yahoo', start_date, end_date)
  close=dataset['Close']
  close_new=close.shift(1)
  close2=close-close_new
  close3=close2.dropna()
  u=close.loc['2012-01-04',tick]
  v=close.loc['2020-06-22',tick]
  c=((v-u)/u)*100
  change.append(c)
print(change.sort())
Roberto Amoroso

The list.sort() method, modifies the list in-place (and returns None). Usually it’s less convenient than sorted() - but if you don’t need the original list, it’s slightly more efficient. Anyway, you can use sorted:

print(sorted(change))

or numpy.sort:

print(np.sort(change))

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I sort a nested list based on numeric values?

How I can sort a list of list in java?

How can I sort (Custom Sort) list of Dictionary entry by value

How to sort the list having float values in python?

Prolog How can I sort a list like this

I have a list contains string and float numbers, how to sort number by descending order and print the list to standard output

How can I convert the list string to a float

how can I sort a list including vectors?

How can I sort this List in julia?

How can I convert a list of strings to an array of float numbers?

How can I sort a List by megapixel and then by name?

How can I sort a list of file names by some substring of the name?

How can I sort List[Int] objects?

How can I use List<object> with Integer and Float ?in java

How can I sort a defaultdict of list by length of list

How can I sort these?

How can I sort a list based on a float inside each string in Python?

how can i sort a list of Multidimension?

How can I sort the lists in the list?

How can I sort a python list by key without .sort()?

How can I convert a list to float inside a for statement

How can I sort a list in python?

How can I sort a list that has a float in string format with a non-numeric value?

How Can i sort the elements inside Local list to specific way

How can I sort a list by matching the words of another list?

How can i sort a laravel's elequent list by another ids

How can I sort elements of list in function?

How can I sort a list of args in Sympy

How can I sort this list by date?