无需手动输入索引即可设置索引(太多),常规数字序列作为索引

Set indices without manually typing them (too many), regular numerical sequences as indices

我有一个包含 1111 行的 pandas 数据框,我想重新索引具有以下名称的行:

前 11 行:

"p000","p100","p200","p300","p400","p500","p600","p700","p800","p900","p1000"

接下来的 100 行:

"p110","p120","p130","p140","p150","p160","p170","p180","p190","p1100",
 "p210","p220","p230","p240","p250","p260","p270","p280","p290","p2100",
 "p310","p320","p330","p340","p350","p360","p370","p380","p390","p3100",
 "p410","p420","p430","p440","p450","p460","p470","p480","p490","p4100",
 "p510","p520","p530","p540","p550","p560","p570","p580","p590","p5100",
 "p610","p620","p630","p640","p650","p660","p670","p680","p690","p6100",
 "p710","p720","p730","p740","p750","p760","p770","p780","p790","p7100",
 "p810","p820","p830","p840","p850","p860","p870","p880","p890","p8100",
 "p910","p920","p930","p940","p950","p960","p970","p980","p990","p9100",
 "p1010","p1020","p1030","p1040","p1050","p1060","p1070","p1080","p1090","p10100"

接下来的 1000 行:

"p1111","p1112","p1113","p1114","p1115","p1116","p1117","p1118","p1119","p11110",
"p1121","p1122","p1123","p1124","p1125","p1126","p1127","p1128","p1129","p11210",
"p1131","p1132","p1133","p1134","p1135","p1136","p1137","p1138","p1139","p11310",
"p1141","p1142","p1143","p1144","p1145","p1146","p1147","p1148","p1149","p11410",
"p1151","p1152","p1153","p1154","p1155","p1156","p1157","p1158","p1159","p11510",
"p1161","p1162","p1163","p1164","p1165","p1166","p1167","p1168","p1169","p11610",
"p1171","p1172","p1173","p1174","p1175","p1176","p1177","p1178","p1179","p11710",
"p1181","p1182","p1183","p1184","p1185","p1186","p1187","p1188","p1189","p11810",
"p1191","p1192","p1193","p1194","p1195","p1196","p1197","p1198","p1199","p11910",
"p11101","p11102","p11103","p11104","p11105","p11106","p11107","p11108","p11109","p111010",

"p1211","p1212","p1213","p1214","p1215","p1216","p1217","p1218","p1219","p12110",
"p1221","p1222","p1223","p1224","p1225","p1226","p1227","p1228","p1229","p12210",
"p1231","p1232","p1233","p1234","p1235","p1236","p1237","p1238","p1239","p12310",
"p1241","p1242","p1243","p1244","p1245","p1246","p1247","p1248","p1249","p12410",
"p1251","p1252","p1253","p1254","p1255","p1256","p1257","p1258","p1259","p12510",
"p1261","p1262","p1263","p1264","p1265","p1266","p1267","p1268","p1269","p12610",
"p1271","p1272","p1273","p1274","p1275","p1276","p1277","p1278","p1279","p12710",
"p1281","p1282","p1283","p1284","p1285","p1286","p1287","p1288","p1289","p12810",
"p1291","p1292","p1293","p1294","p1295","p1296","p1297","p1298","p1299","p12910",
"p12101","p12102","p12103","p12104","p12105","p12106","p12107","p12108","p12109","p121010",

"p1311","p1312","p1313","p1314","p1315","p1316","p1317","p1318","p1319","p13110",
"p1321","p1322","p1323","p1324","p1325","p1326","p1327","p1328","p1329","p13210",
"p1331","p1332","p1333","p1334","p1335","p1336","p1337","p1338","p1339","p13310",
"p1341","p1342","p1343","p1344","p1345","p1346","p1347","p1348","p1349","p13410",
"p1351","p1352","p1353","p1354","p1355","p1356","p1357","p1358","p1359","p13510",
"p1361","p1362","p1363","p1364","p1365","p1366","p1367","p1368","p1369","p13610",
"p1371","p1372","p1373","p1374","p1375","p1376","p1377","p1378","p1379","p13710",
"p1381","p1382","p1383","p1384","p1385","p1386","p1387","p1388","p1389","p13810",
"p1391","p1392","p1393","p1394","p1395","p1396","p1397","p1398","p1399","p13910",
"p13101","p13102","p13103","p13104","p13105","p13106","p13107","p13108","p13109","p131010",

"p1411","p1412","p1413","p1414","p1415","p1416","p1417","p1418","p1419","p14110",
"p1421","p1422","p1423","p1424","p1425","p1426","p1427","p1428","p1429","p14210",
"p1431","p1432","p1433","p1434","p1435","p1436","p1437","p1438","p1439","p14310",
"p1441","p1442","p1443","p1444","p1445","p1446","p1447","p1448","p1449","p14410",
"p1451","p1452","p1453","p1454","p1455","p1456","p1457","p1458","p1459","p14510",
"p1461","p1462","p1463","p1464","p1465","p1466","p1467","p1468","p1469","p14610",
"p1471","p1472","p1473","p1474","p1475","p1476","p1477","p1478","p1479","p14710",
"p1481","p1482","p1483","p1484","p1485","p1486","p1487","p1488","p1489","p14810",
"p1491","p1492","p1493","p1494","p1495","p1496","p1497","p1498","p1499","p14910",
"p14101","p14102","p14103","p14104","p14105","p14106","p14107","p14108","p14109","p141010",

"p1511","p1512","p1513","p1514","p1515","p1516","p1517","p1518","p1519","p15110",
"p1521","p1522","p1523","p1524","p1525","p1526","p1527","p1528","p1529","p15210",
"p1531","p1532","p1533","p1534","p1535","p1536","p1537","p1538","p1539","p15310",
"p1541","p1542","p1543","p1544","p1545","p1546","p1547","p1548","p1549","p15410",
"p1551","p1552","p1553","p1554","p1555","p1556","p1557","p1558","p1559","p15510",
"p1561","p1562","p1563","p1564","p1565","p1566","p1567","p1568","p1569","p15610",
"p1571","p1572","p1573","p1574","p1575","p1576","p1577","p1578","p1579","p15710",
"p1581","p1582","p1583","p1584","p1585","p1586","p1587","p1588","p1589","p15810",
"p1591","p1592","p1593","p1594","p1595","p1596","p1597","p1598","p1599","p15910",
"p15101","p15102","p15103","p15104","p15105","p15106","p15107","p15108","p15109","p151010",

"p1611","p1612","p1613","p1614","p1615","p1616","p1617","p1618","p1619","p16110",
"p1621","p1622","p1623","p1624","p1625","p1626","p1627","p1628","p1629","p16210",
"p1631","p1632","p1633","p1634","p1635","p1636","p1637","p1638","p1639","p16310",
"p1641","p1642","p1643","p1644","p1645","p1646","p1647","p1648","p1649","p16410",
"p1651","p1652","p1653","p1654","p1655","p1656","p1657","p1658","p1659","p16510",
"p1661","p1662","p1663","p1664","p1665","p1666","p1667","p1668","p1669","p16610",
"p1671","p1672","p1673","p1674","p1675","p1676","p1677","p1678","p1679","p16710",
"p1681","p1682","p1683","p1684","p1685","p1686","p1687","p1688","p1689","p16810",
"p1691","p1692","p1693","p1694","p1695","p1696","p1697","p1698","p1699","p16910",
"p16101","p16102","p16103","p16104","p16105","p16106","p16107","p16108","p16109","p161010",

"p1711","p1712","p1713","p1714","p1715","p1716","p1717","p1718","p1719","p17110",
"p1721","p1722","p1723","p1724","p1725","p1726","p1727","p1728","p1729","p17210",
"p1731","p1732","p1733","p1734","p1735","p1736","p1737","p1738","p1739","p17310",
"p1741","p1742","p1743","p1744","p1745","p1746","p1747","p1748","p1749","p17410",
"p1751","p1752","p1753","p1754","p1755","p1756","p1757","p1758","p1759","p17510",
"p1761","p1762","p1763","p1764","p1765","p1766","p1767","p1768","p1769","p17610",
"p1771","p1772","p1773","p1774","p1775","p1776","p1777","p1778","p1779","p17710",
"p1781","p1782","p1783","p1784","p1785","p1786","p1787","p1788","p1789","p17810",
"p1791","p1792","p1793","p1794","p1795","p1796","p1797","p1798","p1799","p17910",
"p17101","p17102","p17103","p17104","p17105","p17106","p17107","p17108","p17109","p171010",

"p1811","p1812","p1813","p1814","p1815","p1816","p1817","p1818","p1819","p18110",
"p1821","p1822","p1823","p1824","p1825","p1826","p1827","p1828","p1829","p18210",
"p1831","p1832","p1833","p1834","p1835","p1836","p1837","p1838","p1839","p18310",
"p1841","p1842","p1843","p1844","p1845","p1846","p1847","p1848","p1849","p18410",
"p1851","p1852","p1853","p1854","p1855","p1856","p1857","p1858","p1859","p18510",
"p1861","p1862","p1863","p1864","p1865","p1866","p1867","p1868","p1869","p18610",
"p1871","p1872","p1873","p1874","p1875","p1876","p1877","p1878","p1879","p18710",
"p1881","p1882","p1883","p1884","p1885","p1886","p1887","p1888","p1889","p18810",
"p1891","p1892","p1893","p1894","p1895","p1896","p1897","p1898","p1899","p18910",
"p18101","p18102","p18103","p18104","p18105","p18106","p18107","p18108","p18109","p181010",

"p1911","p1912","p1913","p1914","p1915","p1916","p1917","p1918","p1919","p19110",
"p1921","p1922","p1923","p1924","p1925","p1926","p1927","p1928","p1929","p19210",
"p1931","p1932","p1933","p1934","p1935","p1936","p1937","p1938","p1939","p19310",
"p1941","p1942","p1943","p1944","p1945","p1946","p1947","p1948","p1949","p19410",
"p1951","p1952","p1953","p1954","p1955","p1956","p1957","p1958","p1959","p19510",
"p1961","p1962","p1963","p1964","p1965","p1966","p1967","p1968","p1969","p19610",
"p1971","p1972","p1973","p1974","p1975","p1976","p1977","p1978","p1979","p19710",
"p1981","p1982","p1983","p1984","p1985","p1986","p1987","p1988","p1989","p19810",
"p1991","p1992","p1993","p1994","p1995","p1996","p1997","p1998","p1999","p19910",
"p19101","p19102","p19103","p19104","p19105","p19106","p19107","p19108","p19109","p191010",

"p11011","p11012","p11013","p11014","p11015","p11016","p11017","p11018","p11019","p110110",
"p11021","p11022","p11023","p11024","p11025","p11026","p11027","p11028","p11029","p110210",
"p11031","p11032","p11033","p11034","p11035","p11036","p11037","p11038","p11039","p110310",
"p11041","p11042","p11043","p11044","p11045","p11046","p11047","p11048","p11049","p110410",
"p11051","p11052","p11053","p11054","p11055","p11056","p11057","p11058","p11059","p110510",
"p11061","p11062","p11063","p11064","p11065","p11066","p11067","p11068","p11069","p110610",
"p11071","p11072","p11073","p11074","p11075","p11076","p11077","p11078","p11079","p110710",
"p11081","p11082","p11083","p11084","p11085","p11086","p11087","p11088","p11089","p110810",
"p11091","p11092","p11093","p11094","p11095","p11096","p11097","p11098","p11099","p110910",
"p110101","p110102","p110103","p110104","p110105","p110106","p110107","p110108","p110109","p1101010"

此外,对于最后 900 行,我需要上面的块,用 2s 替换第一个 1s(p 之后的 1s),下一个块用 3s,下一个块用 4s,...,最后一个块用 10s .手动执行此操作会花费很长时间,我不确定如何编写代码,有什么想法吗?

您可以通过理解轻松构建积木:

前 11 行:

lst1 = [f'p{i}00' for i in range(11)]

接下来的 100 行:

lst2 = [f'p{i}{j}0' for i in range(1, 11) for j in range(1, 11)]

接下来的 1000 行:

lst3 = [f'p1{i}{j}{k}' for i in range(1, 11) for j in range(1, 11)
        for k in range(1,11)]

您的最终名单是 lst1 + lst2 + lst3