gpt4 book ai didi

python - “type”对象不可下标

转载 作者:行者123 更新时间:2023-11-30 22:07:25 25 4
gpt4 key购买 nike

import pandas as pd
import numpy as np

fruits = ["APPLE","BANANA","GRAPES","ORANGE"]
prices = [80,45,60,50]


fru_prices = pd.DataFrame[fruits,prices]

I am getting error while I am creating a Data Frame : 'type' object is not subscriptable

最佳答案

您必须调用DataFrame,然后作为参数执行列表:

fru_prices=pd.DataFrame([fruits,prices])

正如你想要转置的那样:

fru_prices=fru_prices.T

并且需要列:

fru_prices.columns=['fruits','prices']

那么fru_prices就是你想要的

实际上你可以在一行中完成这一切:

fru_prices=pd.DataFrame([fruits,prices],index=['fruit','prices']).T

相关:

See:What does it mean to "call" a function in Python?

关于python - “type”对象不可下标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52463202/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com