fpath=r”C:\Python\WR75\Y Cut\Xpol.txt”
“””
#csv是逗點分隔檔
內容如下:
100.000,10000,11000,12000
-30.000,-70.765,-77.594,-76.722
-29.500,-71.492,-78.381,-76.414
“””
raw_list=[]
with open(fpath, ‘r’) as f:
while True:
aline=f.readline()
print(aline)
if aline == “”: break
raw = aline.strip().split(“,”)
#raw是1D list
raw = [eval(i) for i in raw]
#總是需要印出來,才發現忘記eval()
raw_list.append(raw)
#raw_list是一個2D list
print(“raw:”,raw)
print(“raw_list”,raw_list)
print(type(raw_list))

fpath=r”C:\Python\WR75\Y Cut\Xpol.txt”
raw_list=[]
with open(fpath, ‘r’) as f:
while True:
aline=f.readline()
print(aline)
if aline == “”: break
raw = aline.strip().split(“,”)
raw = [eval(i) for i in raw]
#總是需要印出來,才發現忘記eval()
raw_list.append(raw)
print(“raw:”,raw)
print(“raw_list”,raw_list)
print(type(raw_list))
magind=100
angind=10000
MagIdx = raw_list[0].index(magind)
Idx = raw_list[0].index(angind)
print(MagIdx)
print(Idx)

raw_list[0]
[100.0, 10000, 11000, 12000]
因為檔案是縮小版
沒有0
原始檔案:
100~10000~15000~0~10000~15000
100, 0底下的資料都是角度,非強度
magind=100
angind=10000
MagIdx = raw_list[0].index(magind)
#100這個元素,index=0
Idx = raw_list[0].index(angind)
#10000這個元素,index=1
raw_list[0]
[100.0, 10000, 11000, 12000]


![Python: pandas.Series如何只保留str,去除重複值?#isinstance(x:Any, str) -> bool #.drop_duplicates() #Series.apply( function )逐元素應用function運算 #DataFrame.apply( function )逐Series應用function運算 .drop_duplicates() 跟.unique()有何差別? df.drop_duplicates() 等效於 df[~df.duplicated()] Python: pandas.Series如何只保留str,去除重複值?#isinstance(x:Any, str) -> bool #.drop_duplicates() #Series.apply( function )逐元素應用function運算 #DataFrame.apply( function )逐Series應用function運算 .drop_duplicates() 跟.unique()有何差別? df.drop_duplicates() 等效於 df[~df.duplicated()]](https://i0.wp.com/savingking.com.tw/wp-content/uploads/2024/11/20241123194900_0_5218de.png?quality=90&zoom=2&ssl=1&resize=350%2C233)







近期留言