Transform Columns Example (C#)
[C#]
/* COPYRIGHT(C), SIMPLEXAR SOFTWARE LIMITED, 2006-2008.
* All rights reserved.
*
* Use of this copyright notice is precautionary only, and does not imply
* publication or disclosure. The content of this work contains confidential
* and proprietary information of Simplexar Software Limited. Any duplication,
* modification, distribution, or disclosure in any form, in whole, or in part,
* is strictly prohibited without express prior written permission.
*/
// Get namespaces.
using System;
using Simplexar.Statsar;
using Simplexar.Statsar.Filters;
// Start namespace.
namespace Simplexar.Examples.Statsar
{
/// <summary>
/// This example uses the SheetFilter class to transform data.
/// Two columns are combined to form a new column by using an expression.
/// </summary>
public static class Example
{
/// <summary>
/// The application entry point.
/// </summary>
public static void Main()
{
try
{
RunExample();
}
catch(Exception exception)
{
Console.WriteLine(exception);
}
Console.WriteLine("Press ENTER to terminate.");
Console.ReadLine();
}
private static void RunExample()
{
// Create a calculator.
StatsCalculator calculator = new StatsCalculator();
// Use the calculator to load the sheet.
DataSheet sheet = calculator.Load(
@"..\..\..\..\..\Data\TestScores.csv");
Console.WriteLine(sheet);
// Suppose we wish to create a new data sheet with two columns:
// the student's name, and the total score. The two expressions
// we are looking for are: "Name" and "Total = English + French".
// The first expression means that we wish to select the student's
// name in the resulting sheet. The second expression uses the
// equality operator to mean that we wish to create a new column
// named "Total" which is equal to the sum of the English and
// French scores.
// Configure sheet filter.
SheetFilter filter = new SheetFilter();
filter.Select("Name", "Total = English + French");
// Transform data to produce new sheet.
DataSheet transformSheet = sheet.Filter(filter);
Console.WriteLine(transformSheet);
}
}
}