小编Sam*_* cd的帖子

AttributeError:'Namespace'对象没有属性

我正在编写一个程序,使用urllib2从http站点下载CSV数据.该程序在Python中运行时工作正常,但我也尝试使用argparse来从命令行输入url.

运行时出现以下错误:

File "urlcsv.py", line 51, in downloadData
    return urllib2.urlopen(url)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 127, in urlopen
    return _opener.open(url, data, timeout)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 396, in open
    protocol = req.get_type()
AttributeError: 'Namespace' object has no attribute 'get_type'
Run Code Online (Sandbox Code Playgroud)

我想这是urllib2库的一部分,因为它不是我编写的代码.有没有其他人遇到类似argparseurllib2模块的问题?

代码的相关部分如下:

parser = argparse.ArgumentParser()
parser.add_argument("url")


def main():
    """Runs when the program is opened"""

    args = parser.parse_args()
    if args is False:
        SystemExit
    try:
        csvData = downloadData(args)
    except urllib2.URLError:
        print 'Please try a different URL' …
Run Code Online (Sandbox Code Playgroud)

python

16
推荐指数
2
解决办法
4万
查看次数

将5位数转换为日期

我事先表示歉意,因为我确定之前曾有人问过这个问题,但我不知道我正在使用的日期类型。

如何在SQL Server中将这种5位数字的日期(例如41867)转换为常规的yyyy-dd-mm?

sql sql-server

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

从两个 Pandas 字段创建字典字段

假设我有一个数据框,如:

time    action    player    ...[other fields]
----------------------------------------------
10:00   Buy       A
10:00   Hold      B
09:45   Sell      A
09:45   Buy       B
09:45   Hold      A
09:30   Hold      A
Run Code Online (Sandbox Code Playgroud)

我能够创建一个动作列表 df.groupby('time)['action'].apply(list)

我想创建一个字段,该字段聚合time并从action/创建一个字典player

所以预期输出是:

 time    action    ...[other fields]
----------------------------------------------
10:00   {A:Buy,B:Hold}
09:45   {A:[Sell,Hold],B:Buy}
09:30   {A:Hold}
Run Code Online (Sandbox Code Playgroud)

也许像df.groupby('time)['action'].apply(dict,player=action)

python dictionary pandas

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

标签 统计

python ×2

dictionary ×1

pandas ×1

sql ×1

sql-server ×1