【发布时间】:2022-01-15 18:51:33
【问题描述】:
我有一个 CSV 格式的交易数据,其中包含 Customer ID, Transaction Amount, Transaction Date 列。我有一个接受transactions_csv_file_path as string, N as an integer as params. I want to return the best N customers from the transaction data. NOTE:[最好的客户作为连续每日付款时间最长的客户]`的功能。我可以读取 CSV 如下:
public static string[,] ProcessCSV(string file_path, int n)
{
List<string> transData = new List<string>();
using (StreamReader sr = new StreamReader(file_path))
{
string strResult = sr.ReadToEnd();
var values = strResult.Split(',');
transData.Add(values[0]);
transData.Add(values[1]);
}
return transData.ToArray();
}
调试时,我只得到没有数据的列标题。我想按日期获取每日连续付款并返回customerIds,例如:如果N=1,我希望输出为['K20008'],如果N=3, output: ['K20987', 'K20008', 'K20233']
如何从 CSV 中获取数组数据,并获得最佳的 N 个客户 ID 以及最长的连续每日付款时间?
考虑:define consecutive daily payments as at least 1 transaction per calendar day. and If there are any ties, use ascending order to break ties. For example, K20003 comes before K20005
【问题讨论】: