第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

從熊貓數(shù)據(jù)框列獲取列表

從熊貓數(shù)據(jù)框列獲取列表

慕桂英3389331 2019-10-15 13:54:46
我有一個看起來像這樣的Excel文檔。cluster load_date   budget  actual  fixed_priceA   1/1/2014    1000    4000    YA   2/1/2014    12000   10000   YA   3/1/2014    36000   2000    YB   4/1/2014    15000   10000   NB   4/1/2014    12000   11500   NB   4/1/2014    90000   11000   NC   7/1/2014    22000   18000   NC   8/1/2014    30000   28960   NC   9/1/2014    53000   51200   N我希望能夠?qū)⒘?的內(nèi)容-群集作為列表返回,因此我可以對其運行一個for循環(huán),并為每個群集創(chuàng)建一個excel工作表。還可以將整行的內(nèi)容返回到列表嗎?例如list = [], list[column1] or list[df.ix(row1)]
查看完整描述

3 回答

?
慕容3067478

TA貢獻(xiàn)1773條經(jīng)驗 獲得超3個贊

當(dāng)您將Pandas DataFrame列拉出時,它們就是Pandas Series,然后您可以調(diào)用x.tolist()它們以將其轉(zhuǎn)換為Python列表?;蛘?,您也可以使用list(x)。


import pandas as pd


d = {'one' : pd.Series([1., 2., 3.],     index=['a', 'b', 'c']),

    'two' : pd.Series([1., 2., 3., 4.], index=['a', 'b', 'c', 'd'])}


df = pd.DataFrame(d)


print("Starting with this dataframe\n", df)


print("The first column is a", type(df['one']), "\nconsisting of\n", df['one'])


dfToList = df['one'].tolist()


dfList = list(df['one'])


dfValues = df['one'].values


print("dfToList is", dfToList, "and it's a", type(dfToList))

print("dfList is  ", dfList,   "and it's a", type(dfList))

print("dfValues is", dfValues, "and it's a", type(dfValues))

最后幾行返回:


dfToList is [1.0, 2.0, 3.0, nan] and it's a <class 'list'>

dfList is   [1.0, 2.0, 3.0, nan] and it's a <class 'list'>

dfValues is [ 1.  2.  3. nan] and it's a <class 'numpy.ndarray'>

這個問題可能會有所幫助。一旦您了解了Pandas的風(fēng)格,它們實際上就是相當(dāng)不錯的。


因此,您可以:


my_list = df["cluster"].tolist()


然后從那里去。


查看完整回答
反對 回復(fù) 2019-10-15
?
慕的地10843

TA貢獻(xiàn)1785條經(jīng)驗 獲得超8個贊

這將返回一個numpy數(shù)組:


my_list = df["cluster"].values

這將返回一個numpy數(shù)組,用于唯一值:


my_list = df["cluster"].values

uniqueVals = np.unique(my_list)

或者:


uniqueVals = df["cluster"].unique()


查看完整回答
反對 回復(fù) 2019-10-15
?
吃雞游戲

TA貢獻(xiàn)1829條經(jīng)驗 獲得超7個贊

轉(zhuǎn)換示例:

numpy數(shù)組->熊貓數(shù)據(jù)框->熊貓列中的列表


numpy數(shù)組


data = np.array([[10,20,30], [20,30,60], [30,60,90]])

將numpy數(shù)組轉(zhuǎn)換為熊貓框架


data = np.array([[10,20,30], [20,30,60], [30,60,90]])

dataPd = pd.DataFrame(data = data)


print(dataPd)

    0   1   2

0  10  20  30

1  20  30  60

2  30  60  90

轉(zhuǎn)換一個熊貓框到列表

pdToList = list(dataPd['2'])


遍歷列表作為證明


 for counter, value in enumerate(pdToList):

        print(counter, value)

    0 90

    1 60

    2 30


查看完整回答
反對 回復(fù) 2019-10-15
  • 3 回答
  • 0 關(guān)注
  • 584 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號