Python 在我的情况下,是否可以用更快的(例如应用)替换iterrows?

Python 在我的情况下,是否可以用更快的(例如应用)替换iterrows?,python,pandas,dataframe,bioinformatics,Python,Pandas,Dataframe,Bioinformatics,因此,我有一个如下所示的表: 0 1. 2. 3. 4. 5. rs10000911 4. 144136193 100 - 自动控制 rs10000988 4. 76010255 99.173554 - 银 rs10002181 4. 142250415 100 + 银 rs10005140 4. 22365603 99.173554 + 银 rs10005242 4. 5949558 100 + 银 你可以做: new_col = table.apply(lambda line: pd.Ser

因此,我有一个如下所示的表:

0 1. 2. 3. 4. 5. rs10000911 4. 144136193 100 - 自动控制 rs10000988 4. 76010255 99.173554 - 银 rs10002181 4. 142250415 100 + 银 rs10005140 4. 22365603 99.173554 + 银 rs10005242 4. 5949558 100 + 银 你可以做:

new_col = table.apply(lambda line: pd.Series(str(line[1])+':'+str(line[2])),axis=1)
这将为您提供一个新的数据帧
new\u col

             0
0  4:144136193
1   4:76010255
2  4:142250415
3   4:22365603
4    4:5949558
(如果只需要一个系列,而不是数据帧,
new\u col[0]
将为您提供一个。)

new_col = table.apply(lambda line: pd.Series(str(line[1])+':'+str(line[2])),axis=1)
这将为您提供一个新的数据帧
new\u col

             0
0  4:144136193
1   4:76010255
2  4:142250415
3   4:22365603
4    4:5949558
(如果只需要一个系列,而不是数据帧,
new\u col[0]
将为您提供一个。)

或:

印刷品:

            0  1          2           3  4   5          new
0  rs10000911  4  144136193  100.000000  -  AC  4:144136193
1  rs10000988  4   76010255   99.173554  -  AG   4:76010255
2  rs10002181  4  142250415  100.000000  +  AG  4:142250415
3  rs10005140  4   22365603   99.173554  +  AG   4:22365603
4  rs10005242  4    5949558  100.000000  +  AG    4:5949558
或:

印刷品:

            0  1          2           3  4   5          new
0  rs10000911  4  144136193  100.000000  -  AC  4:144136193
1  rs10000988  4   76010255   99.173554  -  AG   4:76010255
2  rs10002181  4  142250415  100.000000  +  AG  4:142250415
3  rs10005140  4   22365603   99.173554  +  AG   4:22365603
4  rs10005242  4    5949558  100.000000  +  AG    4:5949558
您可以这样做:

df['new_column']=df[1]。astype(str)+:“+df[2]。astype(str)

您可以执行以下操作:


df['new_column']=df[1]。astype(str)+:“+df[2]。astype(str)

不要在数据帧上迭代。请参阅本文中的答案。如果无法使用pandas fanction执行任务,请迭代numpy数组不要迭代pandas DataFrame。请参阅本文中的答案。如果无法使用pandas fanction执行任务,请迭代numpy arraysHello。你是如何在你的帖子中插入这样一个表格的?你好。你是如何在帖子中插入这样一个表格的?