python - 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
解决方案
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
推荐阅读
- git - 当我创建一个新的 git 分支时,我的本地项目文件会发生什么?
- python - 在 numpy 中创建非等距数组的函数
- python - Python Pandas 和 Spearmanr 按行运行更快
- angular - 当我拼接@Input变量时,它反映了父组件的变量
- karate - 如何在后台调用 sql 脚本或查询以获取空手道功能?
- c# - 如何在 c# 中将具有“object”类型的变量转换为具有泛型类型的类?
- c# - C#While循环不起作用
- android - 为什么 Sqlite 只返回最后一行而不是所有行数据?
- npm - package-lock.json 包含非精确版本
- python - 为什么我的列表理解没有显示与 for 循环相同的结果?