1 回答

TA贡献1841条经验 获得超3个赞
我无法通过此处发布的建议获得我想要的东西。不过,我自己也弄明白了。我在这里分享它以供社区参考。
import pandas as pd
import numpy as np
df = pd.DataFrame(columns=[chr(i) for i in range(ord('A'),ord('Z')+1)])
print(df)
Empty DataFrame
Columns: [A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z]
Index: []
[0 rows x 26 columns]
list1 = [i for i in range(101,121)]
arr1d = np.array(list1)
arr1d
array([101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113,
114, 115, 116, 117, 118, 119, 120])
# Create alphabet list of uppercase letters
alphabet = []
for letter in range(ord('C'),ord('W')):
alphabet.append(chr(letter))
alphabet
['C',
'D',
'E',
'F',
'G',
'H',
'I',
'J',
'K',
'L',
'M',
'N',
'O',
'P',
'Q',
'R',
'S',
'T',
'U',
'V']
df = df.append(pd.Series(arr1d, index=alphabet), ignore_index=True)
#This line of code can be used for every new value of arr1d
添加回答
举报