我被困在一个简单的任务上。我想创建一个空的 DataFrame 并根据对另一个数据集的查询向其追加行。我已经尝试过这里的答案,但我错过了一些..初学者 Pythoner。任何帮助,将不胜感激。我想取每个状态的前 3 行并将它们添加到一个新的数据框中进行处理。我也尝试附加..
def test():
#get the list of states
states_df = census_df.STNAME.unique()
population_df = pd.DataFrame()
for st in states_df:
temp_df = pd.DataFrame(census_df[census_df['STNAME'] == st].nlargest(3,'CENSUS2010POP'))
pd.concat([temp_df, population_df], ignore_index = True)
return 1
慕田峪9158850
Cats萌萌
相关分类