简体   繁体   中英

Create a 2D array in Python

I'm trying to create a 2D array that ranges for 1 to 70 years and 1-12 for each year. For example using some kind of for loop to get this below:

EDTI: index = (1,1),(1,2),(1,3)....(1,12), (2,1)...(2,12),(3,1)...(3,12).....(70,12)

and then create a multi-index dataframe.

I want the result of the code below to be in array format that I can set as multi-index.

for j in range(1,71):
    for i in range(1,13)
        print(j,i)

apologies for the bad/vague original question

[[i for i in range(1, 13)] for j in range(1, 71)]

This code uses list comprehension .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM