Skip to content

Instantly share code, notes, and snippets.

View IntegerMan's full-sized avatar
👨‍🔬
Writing "Data Science in .NET with Polyglot Notebooks"

Matt Eland IntegerMan

👨‍🔬
Writing "Data Science in .NET with Polyglot Notebooks"
View GitHub Profile
string text = File.ReadAllText("MyFile.txt");
// Do something with text
LastItemTracker<string> stringTracker = new();
stringTracker.TrackItem("Hello");
stringTracker.TrackItem("World");
Console.WriteLine(stringTracker.LastItem); // Prints out "World"
bool isLastItem = stringTracker.IsLastItem("Hello"); // false
public class LastItemTracker<T>
{
public T LastItem {get; private set;}
public void TrackItem(T item)
{
LastItem = item;
}
public bool IsLastItem(T item)
{
return LastItem == item;
public string CombineTypes<T1, T2>(T1 firstType, T2 secondType)
{
// Implementation omitted...
}
List<int> numbers = new() { 1, 2, 3};
int[] intResults = BuildFirstLastArray<int>(numbers);
List<string> names = new() { "Priya", "Mohammed", "Alexis" };
string[] strResults = BuildFirstLastArray<string>(names);
public T[] BuildFirstLastArray<T>(List<T> input)
{
T[] result = new T[2]();
// For ease of readability, let's just use LINQ here
result[0] = input.First();
result[1] = input.Last();
return result;
}
public string[] BuildFirstLastArray(List<string> input)
{
string[] result = new string[2]();
// For ease of readability, let's just use LINQ here
result[0] = input.First();
result[1] = input.Last();
return result;
}
public int[] BuildFirstLastArray(List<int> input)
{
int[] result = new int[2]();
// For ease of readability, let's just use LINQ here
result[0] = input.First();
result[1] = input.Last();
return result;
}
import pandas as pd
# CSV file is not relevant, just assuming you have some pre-existing data
df = pd.read_csv('models.csv')
# Define columns to add with an array of values for the new row(s)
data = {
"Model":["Linear Regression"],
"R2": [0.042],
"MSE": [3.14],
df = pd.concat([df_new_rows, df])