gpt4 book ai didi

python - 如何按列检查文件中索引的出现并打印出结果

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:46:58 24 4
gpt4 key购买 nike

<分区>

所以我有一个 file1.dat 和我需要检查的索引(逐行)和一个 file2.csv 文件,我想在其中按列计算每个索引的出现次数,然后打印出每个索引的结果。示例:

文件1.dat:

74568
75842
76822
77458

文件 2.csv:

"1470009615","62353","1","y","52669","74568","php"
"1470009617","31173","1","y","54725","31173","php"
"1470009617","16293","1","n","58892","75842","php"
"1470009636","50795","1","y","47004","50795","php"

所以在这种情况下,我想要的是计算 file1.dat 中的每个索引在第 6 列中出现的次数,并生成如下输出 (file3.dat):

74568    1
75842 1
76822 0
77458 0

我知道用 awk 按列计数的代码是这样的:

awk -F, '$6==(index)'

但是我怎样才能让它从列表中获取索引并正确地打印出结果呢?Python 脚本也会有所帮助。

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com