我在R中编写了一个函数,它将包含字母等级的数据框转换为数字等级.然后,我在数据框的每一列上使用sapply().有没有更简单的方法来执行此操作,不需要三次单独调用sapply?有没有办法将函数应用于数据框的每个元素而不是每个行或列?
源数据"成绩"如下所示:
grades <- read.table("Grades.txt", header = TRUE)
head(grades)
final_exam quiz_avg homework_avg
1 C A A
2 C- B- A
3 D+ B+ A
4 B+ B+ A
5 F B+ A
6 B A- A
Run Code Online (Sandbox Code Playgroud)
我的" convert_grades"函数如下所示:
convert_grades <- function(x) {
if (x == "A+") {
x <- 4.3
} else if (x == "A") {
x <- 4
} else if (x == "A-") {
x <- 3.7
} else if (x == "B+") {
x <- …Run Code Online (Sandbox Code Playgroud) 您可以为绘图指定颜色,但Seaborn会在绘图期间稍微将颜色静音.有没有办法关闭这种行为?
例:
import matplotlib
import seaborn as sns
import numpy as np
# Create some data
np.random.seed(0)
x = np.random.randn(100)
# Set the Seaborn style
sns.set_style('white')
# Specify a color for plotting
current_palette = matplotlib.colors.hex2color('#86b92e')
# Make a plot
g = sns.distplot(x, color=current_palette)
Run Code Online (Sandbox Code Playgroud)

# Show what the color should look like
sns.palplot(current_palette)
Run Code Online (Sandbox Code Playgroud)

我已经尝试了几种方法来指定Seaborn中的颜色和所有可用的样式,但没有任何效果.我正在使用iPython笔记本和Python 2.7.