AttributeError:“列表”对象没有属性“ reset_index”

时间:2019-05-20 02:06:56

标签: python pandas

我对熊猫很陌生,使用分组依据时遇到问题。我正在尝试按汽车型号和汽车价值进行分组。我希望它输出每种车型的平均或平均价格。

class Hit extends React.Component{
    constructor(props){
        super(props);
        this.state = {
            attrib1: null,
            attrib2: null
        };
    }

    render() {
        const props = this.props;
        return(
            <a id="cssID" href="/nextpage" onClick={() => this.handleSubmit(props.hit.attrib1, props.hit.attrib2)}>
                <img src={props.hit.image} align="left" alt={props.hit.name} />
                <div className="hit-name">
                    <Highlight className="ais-Highlight-header" attribute="attrib1" hit={props.hit} />
                    <Highlight className="ais-Highlight-state" attribute="attrib2" hit={props.hit} />
                </div>
                <p/>
                <div className="hit-description">
                    <Highlight attribute="attrib3" hit={props.hit} />
                </div>
            </a>
        )
    }
    handleSubmit = (attrib1, attrib2) => {
        this.setState({
            attrib1: attrib1,
            attrib2: attrib2
        });
        console.log(attrib1);//undefined :/
    }

}
model    price
------   ----
honda     2000
Toyota    3000

我不断收到错误消息:AttributeError:'list'对象没有属性'reset_index'

我最初尝试过:

file = pd.read_csv('file.csv')
file2 = pd.read_csv('file2.csv')

file2['price'] = file2['price'].replace('#','')
file['price'] = file['price'].replace('#','')

new = pd.merge(file,file2, on=['col'])

new.drop(['cols'],inplace=True,axis=1)

**new.groupby(['car','price'].reset_index().groupby(['price']).mean(),as_index=True)**

但是它抛出了:new.groupby(['car']).groupby(['price']).mean()

1 个答案:

答案 0 :(得分:0)

您不需要将groupby()与价格结合使用。您可以简单地使用

new.groupby('car').price

访问它。