None of Index are in the columns

拜拜、爱过 提交于 2020-01-16 14:01:11

问题


I'm trying to describe a list values, but this error appears:

KeyError: "None of [Index(['...'],\n dtype='object')] are in the [columns]"

I've tried to search for whitespaces. I've set header to 0 and tried the delim_whitespace=True but there aren't any whitespace so I removed it.

%matplotlib inline
import scipy as sp
import pandas as pd
import matplotlib.pyplot as plt
import statsmodels.formula.api as sm
import csv

df = pd.read_csv('Dados.csv', sep=";", header=0)
x1 = df['com_proc'].values.tolist()
y = df['result_op'].values.tolist()

dados = pd.DataFrame(data=df)
dados

print("Estatísticas descritivas de y:")
dados[y].describe()

Dataframe shows as it should and makes me think that there's nothing wrong with it. The problem starts in the dados[y].describe().


回答1:


df['result_op'] is pointing at the values in the column.
DataFrame.describe() or Series.describe() only works for those with valid names.
dados[y] is not returning anything, let alone dados[y].describe()



来源:https://stackoverflow.com/questions/58595459/none-of-index-are-in-the-columns

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!