以下是我正在处理的问题的一些示例数据:
index Quarter Sales_Growth
0 2001q1 0
1 2002q2 0
2 2002q3 1
3 2002q4 0
4 2003q1 0
5 2004q2 0
6 2004q3 1
7 2004q4 1
Run Code Online (Sandbox Code Playgroud)
该Sales_Growth专栏告诉我该季度是否确实有销售增长。0 = 无增长,1 = 增长。
首先,Quarter当连续两个季度没有销售增长时,我试图返回第一个。
有了上面的数据,这个答案就是2001q1.
然后,我想返回在最初两个季度没有增长之后发生的连续第二个季度的销售增长。
这个问题的答案是2004q4。
我已经搜索过但我能找到的最接近的答案我无法上班:https : //stackoverflow.com/a/26539166/3225420
我是熊猫初学者。
我正在尝试返回索引的元组(下面的人名)和下面'%'列的最大值.当我创建一个Dataframe并尝试
df['%'].max()
Run Code Online (Sandbox Code Playgroud)
Pandas总是只返回值而不是索引.但是,我想从索引的键值对和'%'列中的最大值创建一个元组.我确定这是一个新手问题,谢谢你的帮助!
这是一些示例数据:
Points_Scored Possible_Points % Favoriate Food
Jan 60 200 0.3 Pudding
Jane 87 200 0.435 Pizza
Bob 54 200 0.27 Salad
Bubba 42 200 0.21 Salsa
Jack 98 200 0.49 Avacodo
John 45 200 0.225 Bacon
Mike 63 200 0.315 Tacos
Victor 8 200 0.04 Lettuce
Run Code Online (Sandbox Code Playgroud) 我是我的第一个“真正的”机器学习算法的新手。抱歉,如果这是重复的,但我在 SO 上找不到答案。
我有以下数据框(df):
index Feature1 Feature2 Feature3 Target
001 01 01 03 0
002 03 03 01 1
003 03 02 02 1
Run Code Online (Sandbox Code Playgroud)
我的代码看起来像这样:
data = df[['Feature1', 'Feature2', 'Feature3']]
labels = df['Target']
X_train, X_test, y_train, y_test = train_test_split(data, labels, test_size = 0.8)
clf = RandomForestClassifier().fit(X_train, y_train)
prediction_of_probability = clf.predict_proba(X_test)
Run Code Online (Sandbox Code Playgroud)
我正在苦苦挣扎的是如何才能'prediction_of_probability'回到数据框df?
我知道预测不会适用于原始数据框中的所有项目。
预先感谢您帮助像我这样的新手!
I'm trying to access the RGB color channels of an image using PIL, and then change the color intensity of the color channel of the entire image at once.
When I say RGB color channels, here is an online example.
I don't understand if this has to be done on a pixel by pixel basis or not.
I image the logic of the code would look like this:
import PIL
from PIL import Image
image=Image.open("my_pic.gif")
image=image.convert('RGB')
# made up …Run Code Online (Sandbox Code Playgroud) 我正在尝试每月制作一个箱线图表区域,不同的箱形图按行业分组(并标记),然后让Y轴使用我指定的比例.
在一个完美的世界中,这将是动态的,我可以将轴设置为与整体平均值的一定数量的标准偏差.我可以使用其他类型的动态设置y轴,但我希望它是所有创建的"月度"分组箱图的标准.我不知道处理这个问题的最佳方法是什么,并且对智慧开放 - 我所知道的是现在使用的数字对于图表来说是有意义的.
我已经尝试过所有类型的代码,并且在轴的缩放方面没有运气,下面的代码就像我可以接近图表一样接近.
以下是一些虚拟数据的链接:https: //drive.google.com/open?id = 0B4xdnV0LFZI1MmlFcTBweW82V0k
对于我正在使用Python 3.5的代码:
import pandas as pd
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
matplotlib.use('TkAgg')
import pylab
df = pd.read_csv('Query_Final_2.csv')
df['Ship_Date'] = pd.to_datetime(df['Ship_Date'], errors = 'coerce')
df1 = (df.groupby('Industry'))
print(
df1.boxplot(column='Gross_Margin',layout=(1,9), figsize=(20,10), whis=[5,95])
,pylab.show()
)
Run Code Online (Sandbox Code Playgroud) 我的数据是工厂的缺勤记录。有些日子没有缺席,因此没有记录当天的数据或日期。但是,在显示的其他示例中,这变得令人毛骨悚然,在任何一天,由于各种原因可能会有几次缺席。数据中的日期与记录的比率并不总是 1 比 1。
我希望的结果是这样的:
(index) Shift Description Instances (SUM)
01-01-14 2nd Baker Discipline 0
01-01-14 2nd Baker Vacation 0
01-01-14 1st Cooks Discipline 0
01-01-14 1st Cooks Vacation 0
01-02-14 2nd Baker Discipline 4
01-02-14 2nd Baker Vacation 3
01-02-14 1st Cooks Discipline 3
01-02-14 1st Cooks Vacation 3
Run Code Online (Sandbox Code Playgroud)
等等。这个想法是所有班次和描述都将具有时间段内所有天的值(在本例中为 1/1/2014 - 12/31/2014)
我已经阅读了几个例子,我最接近这个工作的是here。
ts = pd.read_csv('Absentee_Data_2.csv'
, encoding = 'utf-8'
,parse_dates=[3]
,index_col=3
,dayfirst=True
)
idx = pd.date_range('01.01.2009', '12.31.2017')
ts.index = pd.DatetimeIndex(ts.index)
# ts = ts.reindex(idx, fill_value='NaN') …Run Code Online (Sandbox Code Playgroud) 我有一个T-SQL报价表,需要能够计算过去几个月中有多少报价处于未结状态.
我必须使用的日期是' Add_Date'时间戳和' Update_Date'时间戳.一旦引用被放入' Closed_Status'of' 1',它就不能再被更新了.因此,' Update_Date'实际上成为Closed_Status时间戳.
我被困了,因为我无法弄清楚如何选择在特定月份打开的所有公开引号.
这是一些示例记录:
Quote_No Add_Date Update_Date Open_Status Closed_Status
001 01-01-2016 NULL 1 0
002 01-01-2016 3-1-2016 0 1
003 01-01-2016 4-1-2016 0 1
Run Code Online (Sandbox Code Playgroud)
期望的结果是:
Year Month Open_Quote_Count
2016 01 3
2016 02 3
2016 03 2
2016 04 1
Run Code Online (Sandbox Code Playgroud)
我已经在这个问题上打了一个精神墙,我试图做一些case when过滤,但我似乎无法想象出这个难题.理想情况下,我不会在日期中进行硬编码,因为这需要多年时间,而且我不希望在编写之后保持这一点.
预先感谢您的帮助.
我试图获得前一周输入的相关值到下周的输出.
为了这个例子,我已经设置了每周的输入将是下周的输出,并且df.corr()应该给出1.000000结果.
我的原始数据如下所示:
Date Input Output
1/1/2010 73 73
1/7/2010 2 73
1/13/2010 3 2
1/19/2010 4 3
Run Code Online (Sandbox Code Playgroud)
完整示例数据在此处上传:https: //drive.google.com/open?id = 0B4xdnV0LFZI1MzRUOUJkcUY4ajQ
到目前为止,这是我的代码:
import pandas as pd
df = pd.read_csv('pearson.csv')
df['Date'] = pd.to_datetime(df['Date'], errors = 'coerce')
df = df.set_index(pd.DatetimeIndex(df['Date']))
df = df[['Input', 'Output']]
x = df.corr(method = 'pearson', min_periods=1)
print(x)
Run Code Online (Sandbox Code Playgroud)
而作为一个新手在这里,我被卡住了.我没有看到shift函数中内置的选项,也不确定如何执行此操作.
任何和所有的帮助表示赞赏.
谢谢你,我