Your data can be formatted in a few different ways, chief among them wide versus long.
Wide data looks like this:
State
1960
1970
1980
1990
2000
New York
2
5
2
5
4
New Jersey
3
1
4
1
5
Arizona
3
9
8
7
5
While long data looks like this:
State
Year
Value
New York
1960
2
New York
1970
5
New York
1980
2
New York
1990
5
New York
2000
4
New Jersey
1960
3
New Jersey
1970
1
New Jersey
1980
4
…
…
…
Which do you want? Depends on the application! I can think of exactly zero examples at the moment.
Converting between the two
While you could convert between the two in pandas without too much work, I like to use the original data files in my work whenever I can. Not only does it decrease the number of mistakes you might make, but it allows you to easily update to a new release (of the census, for example) by just dropping in a new csv. Converting in d3 isn’t too tough, either.
Usually you can use part of these methods to get to where you’re going, but I’m just going full-out just in case.
Converting Long Data to Wide Data
Your data, which we’ll call long.csv
State
Year
Value
New York
1960
2
New York
1970
5
New Jersey
1960
3
New Jersey
1970
1
Arizona
1960
7
Arizona
1970
2
…
…
…
Your data would look like
Converting Long Data to Wide Data, Method A
Stored in a d3.map()
Using queue
Then, later…
Converting Long Data to Wide Data, Method B
Doesn’t need a d3.map()
Created using d3.nest()
wide would look like
If you left off the last .map() section, wide would be keyed according to the state name, and would not be an array but instead look like this instead: