我有以下数据框:
data = np.random.randn(10,10)
col = list('ABCDEFGHIJ')
idx = list('ababaaccab')
df = pd.DataFrame(data, columns = col, index = idx)
df
A B C D E F H
a -0.104171 -0.872001 1.459766 -0.026101 0.474336 2.032986 -0.795409
b 0.778402 0.965868 1.672520 -2.463641 1.024571 1.501360 1.047823
a 0.731303 -1.314826 1.477969 -1.018818 0.539794 -0.108252 0.038276
b -1.180857 -1.931064 -0.287966 -0.387748 -0.324306 0.146812 0.674937
a -0.151452 0.387804 0.853088 0.610810 0.091901 -0.246471 -0.677219
a 1.392482 1.286639 -0.607495 0.682221 0.164414 -0.496787 0.502786
c 0.039890 0.587645 0.577257 -0.381706 -1.477829 1.165732 -1.877052
c -1.307827 -0.370028 0.136269 -0.968533 0.830933 -0.025641 -0.497450
a 0.990024 0.003812 -0.698894 0.674133 -0.176148 -0.184096 -1.449170
b -1.214920 -1.123358 -0.847955 -0.464895 0.517553 -0.080168 -1.162767
我还使用 pandas 文档中的函数来分隔“元音”和“辅音”之间的字母
def get_letter_type(letter):
if letter.lower() in 'aeiou':
return 'v'
else:
return 'c'
我的问题是如何使用数据框索引中的字母类型进行分组?