簡體   English   中英

如何從輸出列表中刪除 name 和 dtype?

[英]How can I remove name and dtype from my output list?

我一直在用 Python 2 做一個程序,它幫助我添加屬於我的結果列表的所有元素,但我對該列表有一個問題,那就是在我的結果列表中,有些值不是數字,如“名稱” " 和 "dtype" 我無法添加它們。 使用這行代碼“d = df [df ['radio'] == i] ['ParWeight']”,程序所做的是拯救落在半徑小於收音機插上。 每個粒子對應一個半徑和它的權重

import pandas as pd
#Define the data list
weight=[]
data=pd.read_csv('muons.txt',header=0,delim_whitespace=True)
df=pd.DataFrame(data)
#Insert the radio values
R=input('Insert the Radio: ')
for i in df['radio']:
    if i<R:
        d=df[df['radio']==i]['ParWeight']
        weight.append(d) 
print(weight)
[7    2.88072
Name: ParWeight, dtype: float64, 40    5.45978
Name: ParWeight, dtype: float64]
d=df[df['radio']==i]['ParWeight'].iloc[0]
weight.append(d)
print(weight)

iloc 應該能夠在此處隔離字符串值。 由於沒有可用的 df,我無法進行測試。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM