小编chr*_*868的帖子

获取Dataframe Pandas中最高值的列和行索引

我想知道是否有办法找到数据框中最高值的位置(列和行索引).所以,例如,如果我的数据框看起来像这样:

   A         B         C         D         E
0  100       9         1         12        6
1  80        10        67        15        91
2  20        67        1         56        23
3  12        51        5         10        58
4  73        28        72        25        1
Run Code Online (Sandbox Code Playgroud)

如何获得如下结果:[0, 'A']使用Pandas?

python dataframe pandas

7
推荐指数
2
解决办法
5270
查看次数

Python - 显示所有节点属性 Networkx

如何显示节点属性(特别是节点的名称)。这是我到目前为止所拥有的:

import networkx as nx

g = nx.DiGraph()
g.add_node('home')
g.node['home']['value'] = 10
Run Code Online (Sandbox Code Playgroud)

我想要类似的东西

if node_name == 'home' and node[node_name]['value'] == 'somewhere':
    DoSomethingCool()
Run Code Online (Sandbox Code Playgroud)

另外,在使用“get_predecessors”或“get_successors”等函数时,有没有办法访问节点数据?

对此的任何帮助将不胜感激。提前致谢。

python networkx python-3.x

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

lastrowid 在 python 3 的 sqlite3 中返回 None

我在尝试解决在使用 Python 从 SQLite3 中的查询中检索最后一个插入 id 时遇到的问题时遇到了一些麻烦。这是我的代码示例:

import sqlite3

# Setup our SQLite Database
conn = sqlite3.connect('value_serve.db')
conn.execute("PRAGMA foreign_keys = 1") # Enable Foreign Keys
cursor = conn.cursor()

# Create table for Categories
conn.executescript('DROP TABLE IF EXISTS Category;')
conn.execute('''CREATE TABLE    Category (
                id              INTEGER PRIMARY KEY AUTOINCREMENT,
                category        CHAR(132),
                description     TEXT,
                parent_id       INT,
                FOREIGN KEY     (parent_id) REFERENCES Category (id)
                );''')

conn.execute("INSERT INTO Category (category, parent_id) VALUES ('Food', NULL)")
food_category = cursor.lastrowid
conn.execute("INSERT INTO Category (category, parent_id) VALUES ('Beverage', NULL)")
beverage_category …
Run Code Online (Sandbox Code Playgroud)

python sqlite

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

在 WordsNet (Python) 中找到给定多个单词的最低常见上位词

如果我在 python 中有一个单词列表,例如:

words = ["blue", "red", "ball"]
Run Code Online (Sandbox Code Playgroud)

有没有办法使用 WordNet 以编程方式为这组单词生成上位词?

python nlp wordnet hypernym

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

通过分隔符熊猫将列拆分为未知的列数

我试图根据逗号/空格分隔将列拆分为多个列.

我的数据框目前看起来像

    Item                                          Colors
0   ID-1                                          Red, Blue, Green
1   ID-2                                          Red, Blue
2   ID-3                                          Blue, Green
3   ID-4                                          Blue
4   ID-5                                          Red
Run Code Online (Sandbox Code Playgroud)

我想将"颜色"列转换为红色,蓝色和绿色,如下所示:

    Item                                           Red  Blue  Green
0   ID-1                                           1    1     1
1   ID-2                                           1    1     0
2   ID-3                                           0    1     1
3   ID-4                                           0    1     0
4   ID-5                                           1    0     1
Run Code Online (Sandbox Code Playgroud)

我真的不知道该怎么做.任何帮助将不胜感激.

python dataframe pandas data-science

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