I have the below data:
prop_tenure prop_12m prop_6m
0.00 0.00 0.00
0.00 0.00 0.00
0.06 0.06 0.10
0.38 0.38 0.25
0.61 0.61 0.66
0.01 0.01 0.02
0.10 0.10 0.12
0.04 0.04 0.04
0.22 0.22 0.22
Run Code Online (Sandbox Code Playgroud)
and I am doing a pairplot as below:
sns.pairplot(data)
plt.show()
Run Code Online (Sandbox Code Playgroud)
However I would like to display the correlation coefficient among the variables and if possible the skewness and kurtosis of each variable. I am not sure how to do that in seaborn. Can someone please …
我正在尝试创建一个 key:value 对字典,其中 key 是数据框的列名,value 将是一个包含该列中所有唯一值的列表。最终我希望能够从dict 基于条件。到目前为止,这是我能够做的:
for col in col_list[1:]:
_list = []
_list.append(footwear_data[col].unique())
list_name = ''.join([str(col),'_list'])
product_list = ['shoe','footwear']
color_list = []
size_list = []
Run Code Online (Sandbox Code Playgroud)
这里 product,color,size 都是列名,dict 键应该相应地命名为 color_list 等。最终我需要访问字典中的每个 key:value_list。预期输出:
KEY VALUE
color_list : ["red","blue","black"]
size_list: ["9","XL","32","10 inches"]
Run Code Online (Sandbox Code Playgroud)
我有一个pandas数据框,其中包含如下所示的数据:
ID year_month_id Class
1 201612 A
2 201612 D
3 201612 B
4 201612 Other
5 201612 Other
6 201612 Other
7 201612 A
8 201612 Other
9 201612 A
1 201701 B
Run Code Online (Sandbox Code Playgroud)
因此,ID可以在特定月份的任何课程中,下个月他的课程可能会发生变化.现在我要做的是为每个ID获取它在特定类下的月数以及它所属的最新类.如下所示:
ID Class_A Class_B Class_D Other Latest_Class
1 2 3 4 0 B
2 12 0 0 0 D
Run Code Online (Sandbox Code Playgroud)
我如何在python中实现这一点.有人可以帮我这个吗?此外,由于真实数据集很大并且无法手动验证,我如何才能获得超过1类的ID列表?
我试图使用R包mRMRe在Python中进行特征选择,除了这个特征选择部分,所有其他模块都在Python中.
utils = importr('utils') # -- Only once.
utils.install_packages('mRMRe')
# Now we begin by loading in the R packages
pymrmr = importr('mRMRe')
Run Code Online (Sandbox Code Playgroud)
当install_packages部分运行时,我得到:
In[20]: utils.install_packages('mRMRe')
...:
Out[20]: rpy2.rinterface.NULL
Run Code Online (Sandbox Code Playgroud)
我认为安装没有正确发生,因为:
In[19]: pymrmr = importr('mRMRe')
...:
Traceback (most recent call last):
File "C:\hduser\AppData\Local\Continuum\anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2910, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-19-e65c804fa4f7>", line 1, in <module>
pymrmr = importr('mRMRe')
File "C:\hduser\AppData\Local\Continuum\anaconda3\lib\site-packages\rpy2\robjects\packages.py", line 453, in importr
env = _get_namespace(rname)
rpy2.rinterface.RRuntimeError: Error in inDL(x, as.logical(local), as.logical(now), ...) :
**unable to load shared object 'C:/Program …Run Code Online (Sandbox Code Playgroud) 我有以下数据:
grp_m1 grp_m2 grp_m3 grp_m4
$50-$75 $50-$75 $50-$75 $50-$75
$50-$75 $50-$75 $50-$75 $50-$75
$150-$175 $150-$175 $150-$175 $150-$175
$100-$125 $100-$125 $100-$125 $100-$125
$150-$175 $125-$150 $125-$150 $125-$150
Run Code Online (Sandbox Code Playgroud)
然后将它们转换为假人。这些虚拟数据的数据类型在pandas数据帧中是 unsigned int ,当我尝试使用以下代码将其转换为 R 数据帧时:
from rpy2.robjects import pandas2ri
pandas2ri.activate()
pandas2ri.py2ri(data)
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
Error while trying to convert the column "grp_m4_$175-$200". Fall back to string conversion. The error is: Cannot convert numpy array of unsigned values -- R does not have unsigned integers.
(name, str(e)))
C:\Users\hduser\AppData\Local\Continuum\anaconda3.1\lib\site-packages\rpy2-2.9.1-py3.6-win-amd64.egg\rpy2\robjects\pandas2ri.py:61: UserWarning: Error while trying to convert the …Run Code Online (Sandbox Code Playgroud) 我正在使用下面的代码为一个变量绘制两个 kdeplots:
income_df = attrition_df[['Annual Income','Terminated']]
income_left = income_df.loc[income_df['Terminated'] == 1]
income_stayed = income_df.loc[income_df['Terminated'] == 0]
x = np.array(income_left['Annual Income'].values)
y = np.array(income_stayed['Annual Income'].values)
ax = sns.kdeplot(x,y, shade=True)
Run Code Online (Sandbox Code Playgroud)
但我收到一个错误:
ValueError:观察的数量必须大于变量的数量。
我有一个巨大的表(约 8 亿),我需要根据某些段条件获取数据。
数据:
d_id month_id sec average Class
89 201701 S 5.98 A
73 201703 N 7.63 B
31 201708 F 6.38 P
11 201709 K 6.38 P
Run Code Online (Sandbox Code Playgroud)
我有两个清单:
monthList = [201701,201702,201703]
Run Code Online (Sandbox Code Playgroud)
所以sql查询是:
sql_query = str("""select * from dbo.table_name where month_id IN monthList;""")
Run Code Online (Sandbox Code Playgroud)
现在我想将这些数据保存在服务器端游标中,并从中获取基于 classList 的子集
curs = cnxn.cursor('Class')
classList = ['A','B','P']
while True:
records = curs.fetchmany(int(1e3))
if not records:
break
for record in records:
# here I want to use the classList to subset the data , something …Run Code Online (Sandbox Code Playgroud) 我有以下数据:
coll_prop_tenure coll_prop_12m coll_prop_6m coll_prop_3m
0.04 0.04 0.06 0.08
0 0 0 0
0 0 0 0
0.06 0.06 0.1 0
0.38 0.38 0.25 0
0.61 0.61 0.66 0.61
0.01 0.01 0.02 0.02
0.1 0.1 0.12 0.16
0.04 0.04 0.04 0.09
0.22 0.22 0.22 0.22
0.72 0.72 0.73 0.72
0.39 0.39 0.45 0.64
Run Code Online (Sandbox Code Playgroud)
我使用 seaborn 的 distplot 来绘制分布图,如下所示:
######################## density plot #########################################
f, axes = plt.subplots(2, 2, figsize=(7, 7), sharex=True)
sns.distplot( data[cols_viz[0]] , color="skyblue", ax=axes[0, 0])
print("Skewness: %f" % data[cols_viz[0]].skew()) …Run Code Online (Sandbox Code Playgroud) 我目前正在尝试各种方法: 1. 相关性。2. 相互信息。3. 距离相关性以找出 X 中的变量与 y 中的因变量之间的关系强度。关联是最快和最简单的(一个样本 1 小时到 300 万条记录和 560 个变量)。相互信息计算大约需要 16 个小时。我也在研究距离相关性,因为它有一个有趣的特性:Xi 和 Y 之间的距离相关性为零,当且仅当它们是独立的。但是我在用 Python 进行计算时遇到了一个问题。
以下是我的数据:
X
prop_tenure prop_12m prop_6m prop_3m
0.04 0.04 0.06 0.08
0 0 0 0
0 0 0 0
0.06 0.06 0.1 0
0.38 0.38 0.25 0
0.61 0.61 0.66 0.61
0.01 0.01 0.02 0.02
0.1 0.1 0.12 0.16
0.04 0.04 0.04 0.09
0.22 0.22 0.22 0.22
0.72 0.72 0.73 0.72
0.39 0.39 0.45 0.64
**y**
status
0
0 …Run Code Online (Sandbox Code Playgroud) python ×9
pandas ×3
seaborn ×3
r ×2
rpy2 ×2
bigdata ×1
correlation ×1
cursor ×1
dataframe ×1
dictionary ×1
distance ×1
group-by ×1
list ×1
pairwise ×1
postgresql ×1
psycopg2 ×1
scikit-learn ×1