我有以下代码和一个包含5(X和Y)值The Image of the text file is here的文本文件。我需要为每个X和Y值迭代1000次。我怎样才能做到这一点?
import pandas as pd
data = pd.read_csv("test.txt", delim_whitespace=True, skipinitialspace=True,)
for every line in the text document:
for i in range(1, 1001, 1):
z = data["X"] + data["Y"]
z = z + 10
print z
文本文件就像
X Y
1 10
2 20
3 30
4 40
5 50
输出必须是:
10011
10022
10033
10044
10055
答案 0 :(得分:1)
您可以使用var pos = e.clientX - this.$refs._svg.getBoundingClientRect().left;
var refined = Math.max(pos, 0);
refined = Math.min(refined, this.side);
this.position = refined;
选择一行。请阅读此documentation以完全了解这项工作的方式。这是您的数据:
.loc
此代码
import pandas as pd
df = pd.DataFrame({'X':['1','2','3','4','5'], 'Y': ['10','20','30','40','50']})
会给你第一行(索引= 0)作为pandas系列(print df.loc[0]
),它基本上就像一个只有一列的数据帧:一个向量。
pd.Series
如果你想要第二行:X 1
Y 10
Name: 0, dtype: object
等等......
如果你想一次迭代一行,你可以选择第一个for循环中的每一行,并在第二个for循环中执行1000次操作:
df.loc[1]
答案 1 :(得分:1)
试试这个,
FDConnection1.Params.Add('DriverID=ODBC');
FDConnection1.Params.Add('ODBCDriver={Microsoft dBase Driver (*.dbf)}');
FDConnection1.Params.Add('Database=C:\Projects\Test Projects\DBase table\Data');
答案 2 :(得分:0)
如果你想连接'X'和'Y'+'10'那么:
[data.loc[ix]['X'].astype(str) + data.loc[ix]['Y'].astype(str) +"10" for ix in data.index for i in range(1,1001)]
答案 3 :(得分:0)
如果你想要总结' X' +' Y'和concat +' 10'然后:
final_data = [(data.loc[ix]['X'].astype(int) + data.loc[ix]['Y'].astype(int)).astype(str) +"10" for ix in data.index for i in range(1,1001)]
答案 4 :(得分:0)
如果要向dataFrame添加新列:
data["total"] = sorted(set([(data.loc[ix]['X'].astype(int) + data.loc[ix]['Y'].astype(int)).astype(str) +"10" for ix in data.index for i in range(1,1001)]))