Simultaneously merge multiple data.frames in a list

Another question asked specifically how to perform multiple left joins using dplyr in R . The question was marked as a duplicate of this one so I answer here, using the 3 sample data frames below: x <- data.frame(i = c(“a”,”b”,”c”), j = 1:3, stringsAsFactors=FALSE) y <- data.frame(i = c(“b”,”c”,”d”), k = 4:6, stringsAsFactors=FALSE) z … Read more

List of Timezone IDs for use with FindTimeZoneById() in C#?

Here’s a full listing of a program and its results. The code: using System; namespace TimeZoneIds { class Program { static void Main(string[] args) { foreach (TimeZoneInfo z in TimeZoneInfo.GetSystemTimeZones()) { // For a Console App Console.WriteLine(z.Id + “,” + z.BaseUtcOffset + “,” + z.StandardName + “,” + z.DisplayName + “,” + z.DaylightName); // For … Read more

Pandas DataFrame to List of Dictionaries

Use df.to_dict(‘records’) — gives the output without having to transpose externally. In [2]: df.to_dict(‘records’) Out[2]: [{‘customer’: 1L, ‘item1’: ‘apple’, ‘item2’: ‘milk’, ‘item3’: ‘tomato’}, {‘customer’: 2L, ‘item1’: ‘water’, ‘item2’: ‘orange’, ‘item3’: ‘potato’}, {‘customer’: 3L, ‘item1’: ‘juice’, ‘item2’: ‘mango’, ‘item3’: ‘chips’}]

Conversion of System.Array to List

Save yourself some pain… using System.Linq; int[] ints = new [] { 10, 20, 10, 34, 113 }; List<int> lst = ints.OfType<int>().ToList(); // this isn’t going to be fast. Can also just… List<int> lst = new List<int> { 10, 20, 10, 34, 113 }; or… List<int> lst = new List<int>(); lst.Add(10); lst.Add(20); lst.Add(10); lst.Add(34); lst.Add(113); … Read more

Merge two (or more) lists into one, in C# .NET

You can use the LINQ Concat and ToList methods: var allProducts = productCollection1.Concat(productCollection2) .Concat(productCollection3) .ToList(); Note that there are more efficient ways to do this – the above will basically loop through all the entries, creating a dynamically sized buffer. As you can predict the size to start with, you don’t need this dynamic sizing… … Read more

Efficient way to rotate a list in python

A collections.deque is optimized for pulling and pushing on both ends. They even have a dedicated rotate() method. from collections import deque items = deque([1, 2]) items.append(3) # deque == [1, 2, 3] items.rotate(1) # The deque is now: [3, 1, 2] items.rotate(-1) # Returns deque to original state: [1, 2, 3] item = items.popleft() … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)