小编Dhr*_*ati的帖子

AttributeError:'float'对象没有属性'split'

我在说这句话:

lang_modifiers = [keyw.strip() for keyw in row["language_modifiers"].split("|") if not isinstance(row["language_modifiers"], float)]
Run Code Online (Sandbox Code Playgroud)

这似乎适用于row["language_modifiers"]单词(atlas method,central),但不是在它出现时nan.

我认为我if not isinstance(row["language_modifiers"], float)可以抓住事情发生的时间,nan但事实并非如此.

背景:row["language_modifiers"]是tsv文件中的一个单元格,并且nan在被解析的tsv中该单元格为空时出现.

python csv parsing nan

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

无法设置pandas数据框的索引 - 获取"KeyError"

我生成一个看起来像这样的数据框(summaryDF):

   accuracy        f1  precision    recall
0     0.494  0.722433   0.722433  0.722433
0     0.290  0.826087   0.826087  0.826087
0     0.274  0.629630   0.629630  0.629630
0     0.278  0.628571   0.628571  0.628571
0     0.288  0.718750   0.718750  0.718750
0     0.740  0.740000   0.740000  0.740000
0     0.698  0.765133   0.765133  0.765133
0     0.582  0.778547   0.778547  0.778547
0     0.682  0.748235   0.748235  0.748235
0     0.574  0.767918   0.767918  0.767918
0     0.398  0.711656   0.711656  0.711656
0     0.530  0.780083   0.780083  0.780083
Run Code Online (Sandbox Code Playgroud)

因为我知道这行中的每一行应该是什么,然后我使用这段代码来设置每一行的名称(这些不是实际的行名,只是出于参数的缘故).

summaryDF = summaryDF.set_index(['A','B','C', 'D','E','F','G','H','I','J','K','L'])
Run Code Online (Sandbox Code Playgroud)

但是,我得到了:

level = frame[col].values
  File "/Users/me/anaconda/lib/python2.7/site-packages/pandas/core/frame.py", line 1797, …
Run Code Online (Sandbox Code Playgroud)

python row set dataframe pandas

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

-bash:initdb:找不到命令

我已经使用 EnterpriseDB 安装来安装 PostgreSQL。

我运行sudo ./postgresql-9.3.5-3-osx.app/Contents/MacOS/installbuilder.sh --mode unattended然后运行open /Applications/TextEdit.app .profile编辑在 /Users/Dhruv 中新创建的 .profile 文件以添加行source /Library/PostgreSQL/9.3/pg_env.sh.

跑步createuser Dhruv --pwprompt --username=postgres我得到了

-bash:创建用户:找不到命令

然后运行unknown-88-1f-a1-1b-c2-ec:9.3 dhruv$ sudo -u postgres /bin/createuser和各种其他方法我能够使用某种密码提示来设置一些东西。我后来才知道这一点,因为使用sudo -u postgres /Library/PostgreSQL/9.3/bin/createuser我得到了

createuser:创建新角色失败:错误:角色“postgres”已存在

然后运行initdb -D /Library/PostgreSQL/9.3/data I get

-bash:initdb:找不到命令。

同样,如果我在连接到 postgres 时尝试同样的操作,sudo su - postgres然后initdb -D /Library/PostgreSQL/9.3/data我会再次得到

-bash:initdb:找不到命令。

不知所措。1)我如何知道我神奇地创建的这个假定角色“postgres”的详细信息以及2)为什么initdb不工作?

postgresql macos .profile postgresql-9.3

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

附加到集合的对象是 `NoneType` python 2.7

我有大量的标签,我通过以下方式使其独一无二:

unique_train_labels = set(train_property_labels)
Run Code Online (Sandbox Code Playgroud)

打印出来为set([u'A', u'B', u'C']). 我想创建一组新的独特标签,其中包含一个名为“no_region”的新标签,并且正在使用:

unique_train_labels_threshold = unique_train_labels.add('no_region')
Run Code Online (Sandbox Code Playgroud)

然而,这打印出来的是None.

我的最终目标是使用这些独特的标签稍后通过以下方式生成随机的分类标签数组:

    rng = np.random.RandomState(101)

    categorical_random = rng.choice(list(unique_train_labels), len(finalTestSentences))
    categorical_random_threshold = rng.choice(list(unique_train_labels_threshold), len(finalTestSentences))
Run Code Online (Sandbox Code Playgroud)

文档中它说set.add()应该生成一个新的集合,但情况似乎并非如此(因此我以后无法调用list(unique_train_labels_threshold)

python random numpy set python-2.7

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

随机打乱字典列表

我在 Stack Overflow 上看到的一个类似问题涉及列表的 dict(标题不好),当我尝试random.shuffle根据该答案使用我的 dict 列表时,它使整个对象成为 None 类型的对象。

我有一个类似这样的字典列表:

[
{'a':'1211', 'b':'1111121','c':'23423'},
{'a':'101', 'b':'2319','c':'03431'},
{'a':'3472', 'b':'38297','c':'13048132'}
]
Run Code Online (Sandbox Code Playgroud)

我想像这样随机洗牌。

[
{'a':'3472', 'b':'38297','c':'13048132'},
{'a':'1211', 'b':'1111121','c':'23423'},
{'a':'101', 'b':'2319','c':'03431'}   
]
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

python dictionary list

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

使用 `map` 将行写入文件

我有一个行列表:

lines = [a,b,c,d]
Run Code Online (Sandbox Code Playgroud)

以及文件列表(通过open(path string,'w')以下方式创建:

files = [e,f,g,h]
Run Code Online (Sandbox Code Playgroud)

我想要做的是将每一行写入其各自的文件(行a应该与文件e和新行一起使用)。请注意,这是一个更大的循环的一部分,用于生成行并将它们放入您看到的此行列表中:

这是我目前的方法:

map(lambda (x,y): y.write(x) + "\n",zip(lines,files))
Run Code Online (Sandbox Code Playgroud)

但这就是我得到的:

TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
Run Code Online (Sandbox Code Playgroud)

什么是实现我需要的方法?将每一行分别写入每个文件非常麻烦。

python lambda dictionary function python-2.7

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