I am trying to convert the Python code:
df = self.algo.History(
[self.symbol_object],
self.min_bars,
Resolution.Daily
)
# Drops level 0 (Symbols), so only time as index
df.reset_index(level=0, inplace=True)
# Get only the desired columns
columns = ['open', 'high', 'low', 'close', 'volume']
try:
df = df[columns]
# Drop all rows with nans
df.dropna(inplace=True)
except:
self.algo.Debug(f"{self.symbol} ERROR warming up indicators")
return
The call to algo.History returns an IEnumerable<Slice>. How do I take this list and apply:
- df.reset_index()
- df = df[columns]
- df.dropna()
Do I need to walk the enumeration copying over to a new list? I can do that but if there's a C# call that does the equivilent, that would be better I think.
And more basically, do I even need to do this reduction? Or should I skip those 3 steps and iterate through the Slice elements, skipping any that have a N/A? Because I don't see any reason to need to eliminate keys or values when I can just ignore them.
??? - thanks - dave
Manav Trivedi
List<T>.RemoveRange(Int32, Int32) Method is used to remove a range of elements from the List<T>.Â
Example 1:
// C# Program to remove a range of
// elements from the List
using System;
using System.Collections;
using System.Collections.Generic;
 Â
class Geeks {
 Â
   // Main Method
   public static void Main(String[] args)
   {
 Â
       // Creating an List<T> of strings
       List<String> firstlist = new List<String>();
 Â
       // Adding elements to List
       firstlist.Add("Geeks");
       firstlist.Add("For");
       firstlist.Add("Geeks");
       firstlist.Add("GFG");
       firstlist.Add("C#");
       firstlist.Add("Tutorials");
       firstlist.Add("GeeksforGeeks");
 Â
       // Displaying the elements of firstlist
       Console.WriteLine("Elements in List:\n");
 Â
       foreach(string ele in firstlist)
       {
           Console.WriteLine(ele);
       }
 Â
       // removing 1 elements starting
       // from index 3
       firstlist.RemoveRange(3, 1);
 Â
       Console.WriteLine("");
 Â
       // Displaying the updated List
       Console.WriteLine("After Removing of elements:\n");
 Â
       // Displaying the elements in List
       foreach(string ele in firstlist)
       {
           Console.WriteLine(ele);
       }
   }
}
Â
Output:
         Elements in List:
         Geeks
         For
         Geeks
         GFG
         C#
         Tutorials
         GeeksforGeeks
         After Removing of elements:
        Geeks
        For
        Geeks
        C#
        Tutorials
        GeeksforGeeks
Louis Szeto
Hi David and Manav
We can use Linq's .Where() and .Select() methods to wrangle the data since History returns an IEnumerable of Slice objects.
Or if you'd like it to be paired with time:
Best
Louis
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
David Thielen
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!