我有一个数据框,如:
g1 g2 g3 g4 g5
2 0 1 0 1
2 1 1 0 1
2 1 1 2 1
Run Code Online (Sandbox Code Playgroud)
我想删除每个列中至少有一个2的列.
并得到一个新的df:
g2 g3 g5
0 1 1
1 1 1
1 1 1
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助.
我有一个数据框,例如:
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 +
Run Code Online (Sandbox Code Playgroud)
我想删除所有小数并得到:
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 +
Run Code Online (Sandbox Code Playgroud)
我试过:
df['qstart']= round(df['qstart'])
df['qend']= round(df['qend'])
Run Code Online (Sandbox Code Playgroud)
但它不起作用......
python中是否有一种简单的方法可以用另一个替换倍数字符?
例如,我想更改:
name1_22:3-3(+):Pos_bos
Run Code Online (Sandbox Code Playgroud)
至
name1_22_3-3_+__Pos_bos
Run Code Online (Sandbox Code Playgroud)
因此,基本上全部替换"(",")",":"为"_"。
我只知道这样做:
str.replace(":","_")
str.replace(")","_")
str.replace("(","_")
Run Code Online (Sandbox Code Playgroud) I have a list such as:
list=["Chrm_23-56_python_regius","Chrm_3-89_elephant_regius",
"Chrm_13-56_monkey_regius","Chrm_13-34_rat_regius","Chrm_67-123_python_regius",
"chrm_90-345_elephant_regius","Chrm_67-124_monkey_regius",
"Chrm_345-456_rat_regius","Chrm_789-1000_python_regius"]
Run Code Online (Sandbox Code Playgroud)
and the idea is to put all element in a dict form that have the same name (without the number-number) part.
and get something like:
dict = {'key1': ['Chrm_23-56_python_regius','Chrm_67-123_python_regius','Chrm_789-1000_python_regius'],
'key2': ['Chrm_3-89_elephant_regius','chrm_90-345_elephant_regius'],
'key3': ['Chrm_13-56_monkey_regius','Chrm_67-124_monkey_regius'],
'key4': ['Chrm_13-34_rat_regius','Chrm_345-456_rat_regius']}
Run Code Online (Sandbox Code Playgroud)
As you can see for instance, in the key1, the 3 values (without the number-number) are = to Chrm__python_regius.
I know how to see which element is the same without the number-number …