我复制了一些使用 printf 输出字符串在文件中出现的频率的代码。
awk ' BEGIN { print "The number of times a appears in the file:" ; }
/a/ { a_counter+=1 ; }
END { printf "%s\n", a_counter ; }
' $file
Run Code Online (Sandbox Code Playgroud)
将模式修改为变量后,我想将该模式包含到 printf 命令中,位于计数旁边:
awk -v a="$GENE1" ' BEGIN { print "The number of times", a, " appears in the file are:" ; }
$0 ~ a { a_counter+=1 ; }
END { printf "%s\n", a, a_counter ; }
' $file
Run Code Online (Sandbox Code Playgroud)
现在它只打印a的值,而不打印a_counter的值。我读到这printf更复杂,我可能不应该添加用“,”分隔的多个字符串,就像我可以用print. 但我找不到正确的方法?我当然可以坚持下去print …
我用 python 构建了一个绘图仪表板,随着时间的推移显示多个变量。其中一个变量在这里称为“颜色”,我想按它对结果图进行排序。
import pandas as pd
import plotly.express as px
import string
import random
import numpy as np
# for the color mapping
color_dict = {"Colors": {
"green": "rgb(0, 255, 0)",
"black": "rgb(0, 0, 0)",
"red": "rgb(255, 0, 0)"
}}
# creating the df
random.seed(30)
letters = list(string.ascii_lowercase)[0:20]
data = {"letters":letters}
df = pd.DataFrame(data)
df = pd.DataFrame(np.repeat(df.values, 3, axis=0), columns=df.columns) # repeat each row 2 times
df['attempt'] = np.where(df.index%2==0, 1, 2) # adds either 1 or 2 in column …Run Code Online (Sandbox Code Playgroud)