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

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

如何使用 loc[i,j] 根據(jù)索引值訪問數(shù)據(jù)幀中的特定值

如何使用 loc[i,j] 根據(jù)索引值訪問數(shù)據(jù)幀中的特定值

素胚勾勒不出你 2023-11-09 21:39:07
我在txt 文件中有數(shù)據(jù),我將其轉(zhuǎn)換為數(shù)據(jù)幀(data3),我將索引重命名為從 -6 到 +5,現(xiàn)在,在 for 循環(huán)中,我想使用訪問數(shù)據(jù)幀的特定值iloc 命令,但我沒有得到正確的值。數(shù)據(jù)框看起來像這樣如果我使用 data3.iloc[-6,1] 我期望返回值 = -6 但相反,我得到 -20data3.iloc[-5,1] 我原本期待=-20,但結(jié)果卻是-6data3.iloc[-4,1] 我原以為 = -28 但結(jié)果是 -7有人可以幫我嗎?將索引保留在 -6 到 +5 之間對我來說很重要這是我的代碼。謝謝import numpy as npimport pandas as pddata= pd.read_csv('perfilprueba.txt',delimiter=' ')## This is because when I read the txt doesnt read dist and amp as diferent columnsdata_drop = data.drop(data.columns[[1, 2, 3, 4, 6,7]], axis=1) data2=data_drop.rename(columns={"Unnamed: 5": "amp"})## These are two index I will use laterm=int(round(len(data2.index)))n=int(round(m/2))## This is because I wanted that my data had index values from -6 to 5+ AND## also a column with values from -6 to +5r = pd.Series(np.linspace(-n, n-1,m))  data2['r'] = r erre = pd.Series(np.linspace(-n, n-1,m))  data2['erre']=erre data3=data2.set_index('r')## Now I want to run a for loop## that returns me the values of the "amp" column as r moves from -6 to +5ap=[]for r in range(-n,n):     a = data3.loc[[r],['amp']]     ap   += [a]
查看完整描述

2 回答

?
鳳凰求蠱

TA貢獻(xiàn)1825條經(jīng)驗(yàn) 獲得超4個贊

pandas.DataFrame.iloc是“基于純整數(shù)位置的索引,用于按位置選擇”,這意味著當(dāng)您調(diào)用 時(shí)data3.iloc[-5, 1],您實(shí)際上是從數(shù)據(jù)幀末尾的第五行的第二列中獲取。

在你的情況下,我會使用pandas.DataFrame.at,盡管在這種情況下,你也可以使用pandas.DataFrame.loc.

該腳本如下所示:

# reading the data (the "sep=\s+" parameter does what is needed)

data3 = pd.read_csv('perfilprueba.txt', sep="\s+")


m = int(round(len(data3.index)))

n = int(round(m/2))


# changing the index so it starts at -n

data3.index -= n

data3['erre'] = data3.index


ap = []

for r in range(-n,n):

? ? # note that you have to use the column name here

? ? a = data3.at[r,"amp"]

? ? ap.append(a)


查看完整回答
反對 回復(fù) 2023-11-09
?
神不在的星期二

TA貢獻(xiàn)1963條經(jīng)驗(yàn) 獲得超6個贊

按整數(shù)位置訪問行/列對的單個值。
ap=[] for r in range(-n,n): a = data3.?洛克[r]。iat?1?ap += [a]



查看完整回答
反對 回復(fù) 2023-11-09
  • 2 回答
  • 0 關(guān)注
  • 214 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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