我有一個 Pandas 數據框,其中一整列數值應作為來自 的命令的輸入os.system()。這個 os.system() 正在執行一個 .exe 文件,如下所示 os.system(r'xxxx.exe --file "Input_directory" --output "Output_directory" --start 0 --end 10000')此命令中的開始到結束值應該從我的數據幀的列中獲取值。我嘗試循環遍歷我的 df 列。for i in df['xxx']:
os.system(r'xxxx.exe --file "Input_directory" --output "Output_directory" --start i --end i')起始值和結束值可以相同。但是在此命令中循環并輸入變量不起作用。還有其他方法嗎?
2 回答

慕標5832272
TA貢獻1966條經驗 獲得超4個贊
for i in df['xxx']: os.system(r'xxxx.exe --file "Input_directory" --output "Output_directory" --start {} --end {}'.format(i, i))

波斯汪
TA貢獻1811條經驗 獲得超4個贊
嘗試這個
vals = df['col_name'].values.tolist() # Will fetch all the values of that column in a list form
現在您可以嘗試根據需要發送它們
我正在根據我的理解編寫答案,您想要發送列表的第一個和最后一個值
os.system(r'xxxx.exe --file "Input_directory" --output "Output_directory" --start {} --end {}'.format(vals[0], vals[-1]))
添加回答
舉報
0/150
提交
取消