我有一个数据框,例如:
query qstart qend name number strand
A 2.0 1064.0 None 0 +
B 2.0 1076.0 None 0 +
C 2.0 1064.0 None 0 +
D 0.0 741.0 None 0 +
,我想删除所有小数点并得到:
query qstart qend name number strand
A 2 1064 None 0 +
B 2 1064 None 0 +
C 2 1064 None 0 +
D 0 741 None 0 +
我尝试过:
df['qstart']= round(df['qstart'])
df['qend']= round(df['qend'])
但是它不起作用...
答案 0 :(得分:2)
请尝试以下操作:
m=(df.dtypes=='float')
df.loc[:,m]=df.loc[:,m].astype(int)
print(df)
query qstart qend name number strand
0 A 2 1064 None 0 +
1 B 2 1076 None 0 +
2 C 2 1064 None 0 +
3 D 0 741 None 0 +
答案 1 :(得分:1)
df.qend = df.qend.apply(int) # round instead of int is you prefer to round
print (df)
query qstart qend name number strand
0 A 2.0 1064 None 0 +
1 B 2.0 1076 None 0 +
2 C 2.0 1064 None 0 +
3 D 0.0 741 None 0 +