小编MYG*_*YGz的帖子

如何在多个不同的列上应用Count并使用Having子句

我想做这样的事情,但得到一个错误请提出一些好的方法?

select A,B,C, count(Distinct A,B,C)
from table_name 
group by A,B,C 
having count(Distinct A,B,C) > 1 
Run Code Online (Sandbox Code Playgroud)

基本上我有一个列(A,B,C)的索引,有些行没有这个独特的组合集,所以我正在尝试类似的查询来识别违反唯一约束的行.如果有最好的方法,请告诉我

sql oracle indexing count distinct

3
推荐指数
1
解决办法
8459
查看次数

基于过滤器从python列表中删除元素

我在Python中有3个列表.

list_a = [10., 20., 30., 12.]
list_b = [30., 20., 60., 12.]
list_c = [10., 80., 90., 12.]
Run Code Online (Sandbox Code Playgroud)

我想删除这些元素在list_blist_c其中值list_a<= 15.因此结果变为:

list_b = [20., 60.]
list_c = [80., 90.]
Run Code Online (Sandbox Code Playgroud)

有没有办法在没有循环的情况下做到这一点?(列表理解还可以)

python list-comprehension list

3
推荐指数
3
解决办法
654
查看次数

Python斜率(给定两点找到斜率)-answer有效且无效;

试图找出函数以返回Python中直线的斜率。问题的方向是找到具有给定斜率坐标的m的斜率。通读其他一些堆栈溢出文章,但似乎没有一个能解决问题。这是我尝试过的各种变化:

def slope(x1, y1, x2, y2):
    m = 0
    b = (x2 - x1)
    d = (y2 - y1)
    if b != 0:
        m = (d)/(b) 

    return m

slope(2, 3, 6, 7)


def slope(x1, y1, x2, y2):
    m = 0
    a = float(x1)
    b = float(x2)
    c = float(y1)
    d = float(y2)
    m = (d-c)/(b-a)
    return m
slope(2, 3, 6, 7)

def slope(x1, y1, x2, y2):
    m = ''
    a = float(x1)
    b = float(x2)
    c = float(y1)
    d = …
Run Code Online (Sandbox Code Playgroud)

python function line

3
推荐指数
1
解决办法
1万
查看次数

有效地按元素分组

可以说我有

lags = [0, 30, 60, 90, 120, 150, 180, np.inf]
Run Code Online (Sandbox Code Playgroud)

list = [[500, 800, 1000, 200, 1500], [220, 450, 350, 1070, 1780], [900, 450, 1780, 1450, 100], 
        [340, 670, 830, 1370, 1420], [850, 630, 1230, 1670, 910]]

angle = [[50, 80, 100, 20, 150], [22, 45, 35, 107, 178], [90, 45, 178, 145, 10], 
        [34, 67, 83, 137, 142], [85, 63, 123, 167, 91]]
Run Code Online (Sandbox Code Playgroud)

我想将每个元素放在列表中,并根据其值将其存储在不同的单独数组中;

for all list.values where angles.value is less than 30
list1 = [200, 220, …
Run Code Online (Sandbox Code Playgroud)

python sorting performance numpy python-3.x

3
推荐指数
1
解决办法
140
查看次数

can I use applymap to change variable names of dataframe

If I want to change variable names in a data frame using pandas can I change the names without using pandas.df.rename() function but by using applymap() For example

Registrar   Enrolment Agency    State   District    Sub District    Pin Code    Gender
Allahabad Bank  Tera Software Ltd   Jharkhand   Ranchi  Namkum  834003  M
Allahabad Bank  Tera Software Ltd   Jharkhand   Ranchi  Ranchi  834004  F
Allahabad Bank  Vakrangee Softwares Limited Gujarat Surat   Nizar   394380  M
Run Code Online (Sandbox Code Playgroud)

I need to fill spaces in the variable names in the above …

python pandas

3
推荐指数
1
解决办法
468
查看次数

匹配文字字符串 '\$'

我正在尝试匹配文字字符串 '\$'。我通过反斜杠转义了 '\' 和 '$'。为什么当我转义模式中的反斜杠时不起作用?但是如果我使用一个点,那么它就起作用了。

import re

print re.match('\$','\$')
print re.match('\\\$','\$')
print re.match('.\$','\$')
Run Code Online (Sandbox Code Playgroud)

输出:

None
None
<_sre.SRE_Match object at 0x7fb89cef7b90>
Run Code Online (Sandbox Code Playgroud)

有人可以解释一下内部发生了什么吗?

python regex python-2.7

2
推荐指数
1
解决办法
1706
查看次数

Python split()函数如何工作

def loadTest(filename): 
    f=open(filename,'r')
    k=0
    line=f.readline()
    labels=[]
    vectors=[]
    while line and k<4:
        k=k+1
        l=line[:-1].split(r'","')
        s=float(l[0][1:])
        tweet=l[5][:-1]
        print(l)
        line=f.readline()
     f.close()
     return
Run Code Online (Sandbox Code Playgroud)

split(r'","')python split方法实际上做了什么?

python split python-3.x

2
推荐指数
1
解决办法
3456
查看次数

大熊猫数据转换长广

如何从这个表单中获取数据(数据的长表示):

import pandas as pd
df = pd.DataFrame({
    'c0': ['A','A','B'],
    'c1': ['b','c','d'],
    'c2': [1, 3,4]})

print(df)
Run Code Online (Sandbox Code Playgroud)

日期:

   c0 c1  c2
0  A  b   1
2  A  c   3
3  B  d   4
Run Code Online (Sandbox Code Playgroud)

这种形式:

   c0 c1  c2
0  A  b   1
2  A  c   3
3  A  d   NaN
4  B  b   NaN
5  B  c   NaN
6  B  d   4
Run Code Online (Sandbox Code Playgroud)

长期从长到长的转型是这样做的唯一方法吗?

python data-manipulation pandas

2
推荐指数
1
解决办法
123
查看次数

Python:根据替换字典/替换映射替换字符串列表中的匹配项

什么是最好的方法来实现这个目标:

original_list = ["word_1", "word_2", "word"]
replacements = {
  'word_1': 'something',
  'word': 'number'
}
updated_list = replace_in_list(original_list, replacements)
Run Code Online (Sandbox Code Playgroud)

哪里

updated_list == ["something", "word_2", "number"]
Run Code Online (Sandbox Code Playgroud)

python dictionary replace list

2
推荐指数
1
解决办法
102
查看次数

将html表转换为pandas数据帧

我一直在尝试从网站导入一个html表并将其转换为熊猫DataFrame.这是我的代码:

import pandas as pd
table = pd.read_html("http://www.sharesansar.com/c/today-share-price.html")
dfs = pd.DataFrame(data = table)
print dfs 
Run Code Online (Sandbox Code Playgroud)

它只显示这个:

0       S.No                                     ...
Run Code Online (Sandbox Code Playgroud)

但是,如果我这样做;

for df in dfs:
    print df
Run Code Online (Sandbox Code Playgroud)

它输出表..

我怎样才能使用pd.Dataframe刮表?

python quantitative-finance pandas

2
推荐指数
1
解决办法
6207
查看次数