RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / user-508496

Nommad's questions

Martin Hope
Nommad
Asked: 2022-09-08 15:14:49 +0000 UTC

删除二维列表的列表元素而不改变其结构

  • 0

如何在不更改列表结构的情况下删除 2D 列表的第二个元素

[[0,1],[1,9]]-------->[[0,],[1,]]

python
  • 1 个回答
  • 17 Views
Martin Hope
Nommad
Asked: 2022-08-05 18:58:27 +0000 UTC

比较两个DataFrame并输出相同的元素

  • 0

df1

pas_id
923    [0, 0, 1]
987    [0, 0, 1]
127       [0, 1]
215    [0, 0, 1]
254       [2, 2]
302       [0, 1]
350       [0, 1]

df2

           0
0  [0, 0, 1]
1  [0, 0, 1]
2  [0, 0, 1]
3     [2, 2]

如何在 df1 中查找 df2 的元素并显示它们的 pas_id

结论

       (from df1)    (from df2)

923    [0, 0, 1]     [0,0,1]
987    [0, 0, 1]     [0,0,1]
215    [0, 0, 1]     [0,0,1]
254       [2, 2]     [2,2]
python pandas
  • 1 个回答
  • 21 Views
Martin Hope
Nommad
Asked: 2022-08-04 21:40:28 +0000 UTC

在 zip() 之后转换列表

  • 1
# изначально был список
list1 = [[0,0,1],[0,0,1],[0,0,1],[2,2],[1,2,3,4]]
result = []
    for element in list1:
        if len(element )!=2:
            result.append([[x, y] for x,y in zip(element , element[1:])])
        else:
            result.append(element )
print(result)
# 

结论

[[[0, 0], [0, 1]], 
[[0, 0], [0, 1]], 
[[0, 0], [0, 1]], 
[2, 2], 
[[1, 2], [2, 3], [3, 4]]]

期望的输出

[[0,0,1],[0,0,1],[0,0,1],[2,2],[1,2,3,4]]

请告诉我,我在输入时得到这样的列表。我怎样才能把它恢复到原来的格式?在我申请之前zip()。以防万一,我会澄清list1每次都不一样。它是通过 psycopg 从请求中获取的。也就是说,简单地删除一些索引是行不通的。理想情况下是某种验证。我尝试使用len(),但事实证明列表列表中的元素数量[[0, 0], [0, 1]], [2, 2]相同且等于2

python
  • 1 个回答
  • 62 Views
Martin Hope
Nommad
Asked: 2022-09-04 17:10:06 +0000 UTC

不通过 zip 将列表拆分为成对元素

  • 0
list1 = [[0, 0, 1, 2, 3],[3,666]]
result = []
    for cort in list1:
        if len(cort)!=2:
            result.append(list(zip(cort, cort[1:])))
        else:
            result.append(cort)
print(result)

结论

[[(0, 0), (0, 1), (1, 2), (2, 3)],[3,666]]

你可以在没有 的情况下以某种方式做到这一点zip(),它会向我返回一个元组列表,但我需要一个列表列表。

结论

[[[0, 0], [0, 1], [1, 2], [2, 3]],[3,666]]
python
  • 1 个回答
  • 21 Views
Martin Hope
Nommad
Asked: 2022-07-28 15:19:19 +0000 UTC

将字典键写入 csv

  • 0
import pandas as pd

dict_of_right_transitions = {
(0,1):'1',
(0,2):'2',
(0,6):'3',
(1,2):'4',
(1,3):'5',
(1,4):'6',
(1,5):'7',
(1,7):'8'
}
z = pd.DataFrame(list(dict_of_right_transitions.keys()), columns=['first status', 'second status'])
print(z)
z.to_csv(r"C:\\Users\\Users\\PyProj\\Script_check\\dict_of_right_transitions.csv")

结论

    first status  second status
0              0              1
1              0              2
2              0              6
3              1              2
4              1              3
5              1              4
6              1              5
7              1              7

告诉我如何将密钥写入 csv 文件。现在文件被写入一个单元格

完成后的盘子

应该是(无索引)

在此处输入图像描述

python файлы
  • 1 个回答
  • 26 Views
Martin Hope
Nommad
Asked: 2022-07-27 17:22:16 +0000 UTC

检查元组列表中的元素以进行奇偶校验

  • 1
ListWithCortege = [(2, 4, 2, 1, 0), (4, 2, 1, 0), (1, 1, 0), (4, 1), (1, 4, 1),(1,)]

result = []
for cort in ListWithCortege:
    result.append(list(zip(cort, cort[1:])))
for i in result:
    print(i)

结论:

[(2, 4), (4, 2), (2, 1), (1, 0)]
[(4, 2), (2, 1), (1, 0)]
[(1, 1), (1, 0)]
[(4, 1)]
[(1, 4), (4, 1)]
[]

如何在这里进行类型检查:如果元组列表的元素中的元素数 = 1,则添加99999. 对于要(1,)成为的元素(1,99999)。

输出应该是:

[(2, 4), (4, 2), (2, 1), (1, 0)]
[(4, 2), (2, 1), (1, 0)]
[(1, 1), (1, 0)]
[(4, 1)]
[(1, 4), (4, 1)]
[(1,99999)]
python list
  • 2 个回答
  • 29 Views
Martin Hope
Nommad
Asked: 2022-07-26 20:21:32 +0000 UTC

将列表拆分成对

  • 1
ListWithCortege = [(2, 4, 2, 1, 0), (4, 2, 1, 0), (1, 1, 0), (4, 1), (1, 4, 1)]
for item in ListWithCortege:
    print(item)
    for element in item[0:2]:
        print(element)
dict = {
(2,4):'1',
(4,2):'2',
(2,1):'3',
(1,0):'4',
(1,1):'5',
(4,1):'6'
}

结论:

(2, 4, 2, 1, 0)
2
4
(4, 2, 1, 0)
4
2
(1, 1, 0)
1
1
(4, 1)
4
1
(1, 4, 1)
1
4

请告诉我如何从元组的元素中获取交替的数字对? [((2,4),(4,2),(2,1),(1,0)), ((4,2),(2,1),(1,0)), ((1,1),(1,0)), (4,1), ((1,4),(4,1)) )] 然后可以将它们与字典键的值进行比较吗?

python
  • 1 个回答
  • 44 Views
Martin Hope
Nommad
Asked: 2022-07-21 19:14:08 +0000 UTC

功能、选项和 psycopg2

  • 0

函数和参数我搞不清楚(请告诉我,不要扔拖鞋

def get_connect_to_database():
    try:
        connect = psycopg2.connect(dbname = name_of_database, user = user, password = password, host= host)
        print('\n', Fore.GREEN+'================= CONNECTION OK =================')
        print(Fore.RESET)
        cur = connect.cursor()
        time_start = time.time()
    except Exception as _ex:
        print(Fore.RED + '[-Error-]CONNECTION NOT OK', _ex)


def get_query_from_database():
    try:
        get_data_from_first_table = """
            SELECT id,pas_id, date_add, status_id
            FROM status_history 
            where status_id !=7
            and date_add>= now()- interval '10 day'
            order by date_add desc limit 50"""
        cur.execute(get_data_from_first_table)
        data_frame_from_first_table = cur.fetchall()
        print(get_data_from_first_table)
    except Exception as _ex:
        print(Fore.RED + "[-Error-] ERROR WITH QUERY")

如何将cur正确的功能添加到def get_query_from_database(). 他不活跃

python функции
  • 1 个回答
  • 55 Views
Martin Hope
Nommad
Asked: 2022-07-19 22:19:13 +0000 UTC

列表中元素出现频率的图表

  • 1

请告诉我,是否可以绘制列表中元素出现频率的图表?

list_1 = [(1, 4), (1,), (1, 0), (1, 0), (3, 1, 0), (1, 0), (1, 0), (3, 2, 0), (2, 0), (2, 0), (10,), (3, 2, 0), (2, 0)]
c2 = Counter(list_1)
print(c2)

结论:

Counter({(1, 0): 4, (2, 0): 3, (3, 2, 0): 2, (1, 4): 1, (1,): 1, (3, 1, 0): 1, (10,): 1})
python matplotlib
  • 2 个回答
  • 26 Views
Martin Hope
Nommad
Asked: 2022-07-19 20:59:11 +0000 UTC

获取frameframe的一列的元素列表

  • 0

通过 pandas 从 postgresql 中提取了一个框架

密码 status_id
一 0
一 一
一 2
2 7
2 一
3 0
3 四
3 2
3 一

如何从 status_id 列形成一个列表,该列表将对应于 pas_id 列的分组?

它应该是这样的: for pas_id(1) = (0,1,2) for pas_id(2) = (7,1) forpas_id(3) = (0,4,2,1)

全部的:list = [(0,1,2),(7,1),(0,4,2,1)]

python postgresql
  • 1 个回答
  • 22 Views
Martin Hope
Nommad
Asked: 2022-07-14 21:14:07 +0000 UTC

比较或转换两个列表

  • 1

有两个列表。你能告诉我如何比较(或转换和比较)这两个列表并显示列表list_1中不在的元素list_2吗?我是新手,所以不要太苛刻

list_1 = [[1, 7, 0], [1, 7, 0], [1, 7, 0], [3, 1, 7], [1, 7, 0], [1, 7, 0], [3, 1, 7], [3, 1, 7]] <class 'list'>

list_2 =[(2, 7, 0), (7, 2), (7, 1, 7), (1, 3, 7), (0, 7, 1), (7, 1, 3), (1, 7, 0), (3, 1, 7), (3, 2, 7)] <class 'list'>

python
  • 1 个回答
  • 40 Views
Martin Hope
Nommad
Asked: 2022-07-12 16:19:47 +0000 UTC

通过按元素分组来获取列表的元素

  • -1

尊敬的专家。请告诉我。有这样一个清单

cur.execute(get_data_from_first_table)

data_frame_from_first_table = cur.fetchall()

data_frame_from_first_table = [ ('1','1','13:40'), ('1','7','13:39'),('1','0','13:38'),('2','10','12:10'),('2','3','12:09'),('3','6','12:08'),('3','0','11:32'),('3','5','11:31'),('3','8','11:30'),('4','2','10:40'),('4','9','10:39'),('4','10','10:38'), ]

是否有可能以某种方式从每个元素中提取第二个位置,同时按第一个元素对它们进行分组?有点歪曲的解释,但结果应该是这样的:

('1','1','13:40'), ('1','7','13:39'),('1','0','13:38') - 相同的第一个元素,因此写入新列表('1','7','0')

('2','10','12:10'),('2','3','12:09')- 相同的第一个元素,因此写入新列表('10','3')

('3','6','12:08'),('3','0','11:32'),('3','5','11:31'),('3','8','11:30')-('6','0','5','8')

('4','2','10:40'),('4','9','10:39'),('4','10','10:38')-('2','9','10')

输出应该如下:[('1','7','0'), ('10','3'), ('6','0','5', '8'), ('2','9','10')] 等等

python psycopg2
  • 1 个回答
  • 26 Views
Martin Hope
Nommad
Asked: 2022-09-06 14:20:17 +0000 UTC

按 3 个元素拆分列表并与字典进行比较

  • -1

有一个清单。

df = data_frame_from_first_table['status_id'].astype(str).values.tolist()

输出有:

['2', '7', '0', '2', '7', '0', '3', '2', '7', '1', '7', '0', '3', '1', '7', '3', '1', '7', '1', '7', '0']

有一本字典

dict_of_right_transitions = { '1': {'2','7','0'}, '2': {'7','2','3'}, '3': {'7','1','7'}, '4': {'1','3','7'}, '5': {'0','7','1'}, '6': {'7','1','3'} }

您能告诉我如何将列表分成三个元素并与字典进行比较吗?也就是让列表的三个值与字典的值进行比较。

python
  • 1 个回答
  • 38 Views
Martin Hope
Nommad
Asked: 2022-09-04 21:04:55 +0000 UTC

比较表和字典元素

  • 1

这里有张桌子。它记录表中记录从状态到状态的转换历史

ID status_id time_add
一 0 14-10
一 一 13-12
一 7 12-12
2 3 14-09
2 6 14-08
2 7 14-06
3 一 13-11
3 3 12-10
3 一 12-09

使用 pandas 将桌子拉出。数据也按id和时间排序(时间降序排列。) req_2 = pd.DataFrame(mobile_records_2)

还有一个按类型从状态到状态的有效转换字典

dict_1 = {'1':'2', '2':'3', '1':'4', '2':'5', '5':'2', }

从status到status的转换是status_id列的相邻值的组合。也就是说,对于 id = 1,从状态到状态的转换如下:
7 - 1 - 0(0 - 最终和最新状态)在 12 -12,id(1) 的记录处于状态 (7) 然后在 13-12 将状态更改为 (1) 并在 14-10 完成转换并保持状态 (0) 这就是问题,您如何比较从状态到表记录状态的转换是否对应于字典中允许转换?

python
  • 2 个回答
  • 61 Views

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5