对于从非常大的数据框中制作较小的数据框(基于列名)并将其嵌套在字典中的建议,我将不胜感激。因此,在下面的示例中,它并没有满足我的要求,我想要一本名为Country的字典,它带有两个键(NJ和NY)。在NJ中,我想要另一个带有三个键(北,南和西)的字典。在北方,我想要数据框(或系列)NJ_North。
import pandas as pd
States = ['NJ', 'NY']
Areas = ['North','South','West']
dfAreas = pd.DataFrame([[10,11,12,13,14,15],[16,17,18,19,20,21]],
columns=['NJ_North','NJ_South','NJ_West','NY_North','NY_South','NY_West'])
Country = {}
for State in States:
for Area in Areas:
Country[State] = dfAreas.filter(like=State, axis=1)
Country[Area] = dfAreas.filter(like=Area, axis=1)