我一直在寻找通过python文档和论坛选择列的方法,但索引列上的每个示例都过于简单.
假设我有一个10 x 10的数据帧
df = DataFrame(randn(10, 10), index=range(0,10), columns=['A', 'B', 'C', 'D','E','F','G','H','I','J'])
Run Code Online (Sandbox Code Playgroud)
到目前为止,所有文档都只是一个索引的简单例子
subset = df.loc[:,'A':'C']
Run Code Online (Sandbox Code Playgroud)
要么
subset = df.loc[:,'C':]
Run Code Online (Sandbox Code Playgroud)
但是当我尝试索引多个非顺序列时,我得到一个错误,就像这样
subset = df.loc[:,('A':'C', 'E')]
Run Code Online (Sandbox Code Playgroud)
如果我想从A到C,E和G中选择A列,我将如何在Pandas中编入索引?看来这个逻辑不起作用
subset = df.loc[:,('A':'C', 'E', 'G':'I')]
Run Code Online (Sandbox Code Playgroud)
我觉得解决方案非常简单,但我无法解决这个错误.谢谢!
El Capitan OS在这里.我一直试图找到一个解决方法,导入Tensorflow到我的ipython笔记本,但到目前为止没有运气.
像论坛中的很多人一样,由于六个包,我也遇到了安装张量流问题.我可以在使用brew进行一些烦躁之后安装
brew link gdbm
brew install python
rew linkapps python
sudo pip install https://storage.googleapis.com/tensorflow/mac/tensorflow-0.5.0-py2-none-any.whl
Run Code Online (Sandbox Code Playgroud)
我收到一条消息,表明tensorflow已正确安装.即使我这样做,sudo pip install tensorflow我收到的消息:
Requirement already satisfied (use --upgrade to upgrade): tensorflow in /usr/local/lib/python2.7/site-packages
Requirement already satisfied (use --upgrade to upgrade): six>=1.10.0 in /Library/Python/2.7/site-packages (from tensorflow)
Requirement already satisfied (use --upgrade to upgrade): numpy>=1.9.2 in /usr/local/lib/python2.7/site-packages (from tensorflow)
Run Code Online (Sandbox Code Playgroud)
但是,当我在我的ipython笔记本上并且我做了一个时,import tensorflow我收到了消息:ImportError: No module named tensorflow
我进一步挖了并在导入时发现了这个错误:
In [1]: import tensorflow
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-a649b509054f> in …Run Code Online (Sandbox Code Playgroud) 希望我读错了,但是在XGBoost库文档中,有一些提示使用feature_importances_很多像sklearn的随机森林来提取特征重要性属性.
但是,出于某种原因,我不断收到此错误: AttributeError: 'XGBClassifier' object has no attribute 'feature_importances_'
我的代码段如下:
from sklearn import datasets
import xgboost as xg
iris = datasets.load_iris()
X = iris.data
Y = iris.target
Y = iris.target[ Y < 2] # arbitrarily removing class 2 so it can be 0 and 1
X = X[range(1,len(Y)+1)] # cutting the dataframe to match the rows in Y
xgb = xg.XGBClassifier()
fit = xgb.fit(X, Y)
fit.feature_importances_
Run Code Online (Sandbox Code Playgroud)
您似乎可以Booster通过调用get_fscore属性来使用对象计算要素重要性.我使用的唯一理由XGBClassifier了Booster,是因为它能够被包裹在一个sklearn管道.有关功能提取的任何想法?还有其他人遇到过这种情况吗?
当我的图表使用{{ include }}. 例如,我的清单看起来像这样
containers:
- name: {{ .Release.Name }}
image: {{ .Values.global.image}}:{{ .Values.global.imageTag }}
imagePullPolicy: {{ .Values.global.pullPolicy }}
ports:
- containerPort: {{ .Values.gloabl.containerPort }}
{{ include "common_deployment" . }}
Run Code Online (Sandbox Code Playgroud)
我common_deployment的定义为
{{- define "common_deployment" }}
envFrom:
- secretRef:
name: {{ .Release.Name }}-secret
{{- end -}}
Run Code Online (Sandbox Code Playgroud)
当我在 Helm 上进行试运行后查看我的清单时,我的模板看起来像这样
containers:
- name: test
image: myrepo/myimage:latest
imagePullPolicy: Always
ports:
- containerPort: 4444
envFrom:
- secretRef:
name: test-secret
Run Code Online (Sandbox Code Playgroud)
请注意在ports和之间有一个新的谎言envFrom。我想知道这是否会影响我的 pod 的结果,因为安装卷时存在问题,我希望能够在进入另一个兔子洞之前确保这个模板问题是罪魁祸首。
假设我有类别,1到10,我想分配red值3到5,分别green为1,6和7,以及blue分配给2分,8分,9分和10分.
我该怎么做?如果我试试
df.cat.rename_categories(['red','green','blue'])
Run Code Online (Sandbox Code Playgroud)
我收到一个错误:ValueError: new categories need to have the same number of items than the old categories!但是如果我把它放进去的话
df.cat.rename_categories(['green','blue','red', 'red', 'red'
'green', 'green', 'blue', 'blue' 'blue'])
Run Code Online (Sandbox Code Playgroud)
我会收到一个错误,说有重复的值.
我能想到的唯一另一种方法是编写一个for循环,它将遍历值的字典并替换它们.是否有更优雅的解决方案?
我有两个大表,old_customers 和 new_customers,我想对它们进行行绑定。这已完成,但其中任何一个都太大而无法加载到内存中。但是,我不确定是否bind_rows允许绑定两个表而不是两个数据框。我尝试时收到此错误
old <- tbl(conn, 'old_customers')
new <- tbl(conn, 'new_customers')
old %>% bind_rows(new)
Error in bind_rows_(x, .id) :
Argument 1 must be a data frame or a named atomic vector, not a tbl_dbi/tbl_sql/tbl_lazy/tbl
Run Code Online (Sandbox Code Playgroud)
另一种选择是这样的
old <- as.data.frame(tbl(conn, 'old_customers'))
new <- as.data.frame(tbl(conn, 'new_customers'))
old %>% bind_rows(new)
Run Code Online (Sandbox Code Playgroud)
但同样,我试图避免将此数据集加载到内存中。有没有解决的办法?
我试图更多地了解这个caret包,并遇到了一个我不确定如何解决的障碍.
#loading up libraries
library(MASS)
library(caret)
library(randomForest)
data(survey)
data<-survey
#create training and test set
split <- createDataPartition(data$W.Hnd, p=.8)[[1]]
train<-data[split,]
test<-data[-split,]
#creating training parameters
control <- trainControl(method = "cv",
number = 10,
p =.8,
savePredictions = TRUE,
classProbs = TRUE,
summaryFunction = "twoClassSummary")
#fitting and tuning model
tuningGrid <- data.frame(.mtry = floor(seq(1 , ncol(train) , length = 6)))
rf_tune <- train(W.Hnd ~ . ,
data=train,
method = "rf" ,
metric = "ROC",
trControl = control)
Run Code Online (Sandbox Code Playgroud)
不断收到错误:
Error in evalSummaryFunction(y, …Run Code Online (Sandbox Code Playgroud) 我正在尝试构建一个正则表达式模式,该模式将从字符串中删除标点符号。我决定punctuation从string图书馆使用。但是,当我执行它时,Spark 返回一个错误,指出有一个未包含的字符。
我怀疑其中的字符punctuation在执行过程中关闭了引号。我有一种感觉,这应该很容易解决,但我不确定如何解决。我的代码如下:
from pyspark.sql.functions import regexp_replace, trim, col, lower
import string
def removePunctuation(column):
no_punct = regexp_replace(column, string.punctuation, '')
lowered = lower(no_punct)
cleaned = strip(lowered)
return cleaned
Run Code Online (Sandbox Code Playgroud)
我得到这个错误 org.apache.spark.SparkException: Job aborted due to stage failure: Task 0 in stage 86.0 failed 1 times, most recent failure: Lost task 0.0 in stage 86.0 (TID 3709, localhost): java.util.regex.PatternSyntaxException: Unclosed character class near index 31
我正在使用 dplyr 在 Redshift 中执行某些操作,因此我不会将数据加载到内存中。
data <- tbl(conn, "customers") %>%
filter(age >= 18)
subset <- data %>%
filter(eye_color != "brown") %>%
group_by(gender, method, age, region) %>%
summarise(sum(purchases)) %>% # will create a column called sum(purchases)
full_join(data, by=c("region", "age", "method"))
Run Code Online (Sandbox Code Playgroud)
现在,当我查看生成的数据帧时,我将看到一个名为的列sum(purchases),我想将其重命名为purchases将创建列,purchase.x并purchase.y在合并之后。
到目前为止,我读过的大多数重命名都是处理内存中的数据帧,而不是使用 dbplyr 延迟评估的数据帧。我尝试过使用rename,rename_以及rename_at的不同变体select。我也尝试过这里和这里列出的策略,但没有运气
有没有办法重命名sum(purchases). 我唯一的其他选择是在某个步骤将数据帧加载到内存中
data <- tbl(conn, "customers") %>%
filter(age >= 18)
subset <- data %>% …Run Code Online (Sandbox Code Playgroud) python ×5
r ×3
dplyr ×2
pandas ×2
apache-spark ×1
dbplyr ×1
go ×1
kubernetes ×1
pyspark ×1
r-caret ×1
scikit-learn ×1
tensorflow ×1
xgboost ×1
yaml ×1