首页 > 解决方案 > Facing error while creating dataframe in loops

问题描述

This is my code:

models = data['ModelG'].unique()
#ModelG is the column where i have different brands, 'data' is my database

for i in models:
    datacut = data[data['ModelG']== models[i]]
# I want to make different dataframe by unique values in column m

How can I resolve the following error?

Error: IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices

标签: pythonloops

解决方案


Try this :

models = data['ModelG'].unique()
#ModelG is the column where i have different brands, 'data' is my database

for i in models:
    datacut = data[data['ModelG']== i]
# I want to make different dataframe by unique values in column m

推荐阅读