(我添加了类型并修正了一些错误)
type StateEdu =
{ State : string
Education : int
Income : float }
type StateFamily =
{ State : string
PctMoreThan4Children : float
PctFamilyMorethan3 : float }
//I added this new type so this is value of the final map.
type State2 =
{ State : string
StateEdu : StateEdu
StateFamily : StateFamily }
//Instead providing the csv it's better to minimize the example, so here are the two record lists.
let stateEdu =
[{State = "TX"; Income = 51522.; Education = 0}
{State = "AL"; Income = 6481.; Education = 1}
{State = "MO"; Income = 78921.; Education = 1}
{State = "TN"; Income = 12000.; Education = 4}
{State = "PA"; Income = 79850.; Education = 2}
{State = "NY"; Income = 79215.; Education = 1}
{State = "CA"; Income = 79045.; Education = 2}]
let datafamily =
[{State = "TX"; PctMoreThan4Children = 51.52; PctFamilyMorethan3 = 65.0}
{State = "AL"; PctMoreThan4Children = 64.00; PctFamilyMorethan3 = 51.4}
{State = "MO"; PctMoreThan4Children = 78.92; PctFamilyMorethan3 = 25.1}
{State = "TN"; PctMoreThan4Children = 12.00; PctFamilyMorethan3 = 62.1}
{State = "PA"; PctMoreThan4Children = 8.50; PctFamilyMorethan3 = 41.2}
{State = "NY"; PctMoreThan4Children = 25.15; PctFamilyMorethan3 = 31.0}
{State = "CA"; PctMoreThan4Children = 79.5; PctFamilyMorethan3 = 50.5}]
let stateedu =
stateEdu
|> Seq.map (fun x -> x.State,x)
|> Map.ofSeq
let datafam =
datafamily
|> Seq.map (fun x -> x.State,x)
|> Map.ofSeq
//This is one way to quickly extract the keys
let stateall = stateedu |> Map.toSeq |> Seq.map fst
//We go through all the keys
let statedatamap =
stateall
|> Seq.map (fun state ->
state,
{State = state //this is the State2type
StateEdu = stateedu.[state]
StateFamily = datafam.[state]
})
|> Map.ofSeq
stateedu=state=“al”;
pctmorethan4children=64.0;
(“CA”,state=“CA”;
stateedu=state=“ca”;
stateFamily=state=“ca”;
pctfamilymorethan3=50.5;);
(“NY”,state=“NY”;
教育=1;
(“pa”,state=“pa”;
stateFamily=state=“pa”;
(“tn”,state=“tn”;
教育=4;
PCTMorethan4儿童=12.0;
(“tx”,state=“tx”;
收入=51522.0;;
PCTMorethan4儿童=51.52;
statedu.[state].Education
例如。