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)
添加回答
舉報(bào)