自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

利用ChatGPT進行數(shù)據(jù)清洗處理

原創(chuàng) 精選
開發(fā)
最近chatgpt非?;?,通過chatgpt可以做很多事情,筆者也通過實際使用解決了自己的問題,都基本不用自己編程。

最近chatgpt非?;?,通過chatgpt可以做很多事情,筆者也通過實際使用解決了自己的問題,都基本不用自己編程。

本文主要需要解決:

通過burpsuite批量獲取的json文件,需要處理成mysql數(shù)據(jù)庫識別的格式,方便入庫。

(1)重命名所有文件為txt后綴文件

(2)刪除txt文件無用的前N行數(shù)據(jù),其實就是頭文件數(shù)據(jù),有幾行就定義幾行。

(3)重命名txt文件為json文件。

(4)對json文件自動識別表列名,并處理數(shù)據(jù)到一個文件中。

1.chatgpt嘗試  

 通過fofa.info搜索"loading-wrap" && "balls" && "chat" && is_domain=true,搜索的記錄就是提供chatgpt的網(wǎng)站地址。

圖片

2.逐個網(wǎng)站測試是否可以免費使用

 打開搜索中的記錄,逐個查看,有的需要輸入密碼才能方法,尋找一些免費的chatgpt。

圖片

 對一些需要輸入驗證的直接pass掉,然后尋找一些不需要密碼就能訪問的。例如https://chat.77yun.cc/#/chat/1002

圖片

3.進行實際測試

 可以在chatgpt中將自己的問題提出來,輸入回車后即可獲取相應的解決方法。同時對實際數(shù)據(jù)進行測試,不斷的訓練,最后達到自己想要的結果。

圖片

圖片

4.最后的代碼為

import os
import json


#獲取指定目錄下所有的文件
dir = 'all'
all_files = [f for f in os.listdir(dir) if os.path.isfile(os.path.join(dir, f))]


for file in all_files:
    #將所有擴展名不是.txt的文件改名為同名.txt文件
    if not file.endswith('.txt'):
        os.rename(os.path.join(dir, file), os.path.join(dir, os.path.splitext(file)[0] + '.txt'))
        file = os.path.splitext(file)[0] + '.txt'
    
    #對于每個txt文件,刪除前9行的內容并保存到新的txt文件中
    with open(os.path.join(dir, file), 'r', encoding='utf-8') as txt_file:
        content = txt_file.readlines()


    deleted_content = '\n'.join(content[:9])
    new_content = ''.join(content[9:])
    with open(os.path.join(dir, file), 'w', encoding='utf-8') as txt_file:
        txt_file.write(new_content)
    
    #將新的txt文件重命名為同名.json文件,并讀取其內容
    json_file = os.path.splitext(file)[0] + '.json'
    os.rename(os.path.join(dir, file), os.path.join(dir, json_file))
    
    with open(os.path.join(dir, json_file), 'r', encoding='utf-8') as j_file:
        data = json.load(j_file)
        columns = list(data['page']['list'][0].keys())
        rows = []
        
        for item in data['page']['list']:
            row_values = []
            for column in columns:
                value = str(item[column]).replace('\n','').replace(',','')
                row_values.append(value)
            rows.append(','.join(row_values))
        
        #整理json文件中的數(shù)據(jù),并按照列名的順序寫入數(shù)據(jù)文件out.txt中
        with open('out.txt', 'a+', encoding='utf-8') as out_file:
            if out_file.tell() == 0:
                out_file.write(','.join(columns) + '\n')
            out_file.write('\n'.join(rows)+'\n')
        
        print("文件{}中的數(shù)據(jù)已寫入out.txt文件中".format(json_file))

5.總結

  使用chatgpt編程非常簡單,關鍵你需要定義好你需要的東西。例如我的功能描述如下:

(1)使用python代碼實現(xiàn)以下功能:當前數(shù)據(jù)目錄為all

(2)原始代碼中首先對所有文件重命名為文件ren *.* *.txt 

(3)獲取指定目錄下所有的文件,并遍歷每個文件。

(4)將所有擴展名不是 .txt 的文件重命名為同名的 .txt 文件,保證后續(xù)處理只考慮 txt 文件。

(5)對于每個txt文件,讀取文件內容并刪除前9行的內容,這一部分數(shù)據(jù)在原代碼中被稱為“頭部內容”,然后將剩余內容保存到新的txt文件中。

(6)將新的txt文件重命名為同名 .json 文件,并讀取其內容。

(7)整理 json 文件中的數(shù)據(jù),并按照列名的順序寫入數(shù)據(jù)文件out.txt中。

 需要清晰的定義好想要的功能點,然后通過不停的訓練測試最終達到自己想要的效果。總之有了chatgpt后,你有產品的思路就可以,很多功能可以簡化,有編程功底的人可以更好的利用。

責任編輯:龐桂玉 來源: 51CTO
相關推薦

2023-05-05 19:16:22

Python數(shù)據(jù)清洗

2024-12-19 15:00:00

數(shù)據(jù)清洗Python

2025-04-07 00:30:00

DeepSeek大數(shù)據(jù)數(shù)字化

2024-10-28 12:57:36

Pandas數(shù)據(jù)清洗

2022-03-28 14:08:02

Python數(shù)據(jù)清洗數(shù)據(jù)集

2023-05-30 18:05:00

chatgpthtml

2023-09-26 01:03:36

Pandas數(shù)據(jù)數(shù)據(jù)集

2021-07-27 15:40:39

Python數(shù)據(jù)清洗函數(shù)

2018-04-03 12:07:53

數(shù)據(jù)清洗PandasNumpy

2010-01-06 14:36:04

JSON插件

2020-06-05 14:29:07

PythonPandas數(shù)據(jù)分析

2012-03-21 09:31:51

ibmdw

2018-05-07 14:50:27

可視化數(shù)據(jù)散點圖

2023-09-27 15:34:48

數(shù)據(jù)編程

2024-07-26 21:36:43

2017-12-11 09:03:31

2021-07-17 22:41:53

Python數(shù)據(jù)技術

2022-01-26 09:00:00

數(shù)據(jù)庫SnowparkSQL

2022-01-21 13:53:29

云計算邊緣計算數(shù)據(jù)

2017-10-31 11:55:46

sklearn數(shù)據(jù)挖掘自動化
點贊
收藏

51CTO技術棧公眾號