如何使用Python實(shí)現(xiàn)數(shù)據(jù)透視表、音頻文件格式轉(zhuǎn)換
用Python實(shí)現(xiàn)數(shù)據(jù)透視表、音頻文件格式轉(zhuǎn)換
1.用Python實(shí)現(xiàn)數(shù)據(jù)透視表
import pandas as pd if __name__ == '__main__': # df = pd.read_excel('廣告-資源位變現(xiàn)效率監(jiān)測(cè)看板-1.xlsx', sheet_name='各業(yè)務(wù)在該資源位的明細(xì)數(shù)據(jù)') df = pd.read_excel('填充率分析-Q3.xlsx', sheet_name='庫存底表') df = df.loc[df['dt'].str.startswith('2023-09-21')] # df = df.loc[df['dt'].str.startswith('2023-09-')] df = df.loc[df['資源位'] == '亮屏貼片'] # df = df.loc[df['業(yè)務(wù)類型'] == '品牌廣告'] total = df['庫存'].sum() print(total)
2.用Python實(shí)現(xiàn)音頻文件格式轉(zhuǎn)換
from pydub import AudioSegment import os def add_path(): path = os.environ.get('PATH') path = path[:-1] # new_path = 'C:\\Program Files\\gs\\gs10.01.2\\bin;.' new_path = 'C:\\myPC\\tools\\ffmpeg\\bin;.' updated_path = path + new_path os.environ['PATH'] = updated_path def convert_m4a_to_wav(input_file, output_file): audio = AudioSegment.from_file(input_file, format="m4a") audio.export(output_file, format="wav", parameters=["-ar", "16000"]) print(f"Duration of {output_file}: {audio.duration_seconds} seconds") return audio.duration_seconds if __name__ == '__main__': add_path() directory = "./M4A/" files = os.listdir(directory) total_seconds = 0.0 for file in files: print("Processing ", file) file = file.replace(".m4a", "") total_seconds = total_seconds + convert_m4a_to_wav("./M4A/" + file + ".m4a", "./WAV/" + file + ".WAV") total_minutes = total_seconds / 60.0 total_hours = total_minutes / 60.0 print("Total: " + str(total_seconds) + " sec; ") print("Total: " + str(total_minutes) + " min; ") print("Total: " + str(total_hours) + " hour; ")
到此這篇關(guān)于用Python實(shí)現(xiàn)數(shù)據(jù)透視表、音頻文件格式轉(zhuǎn)換的文章就介紹到這了,更多相關(guān)Python數(shù)據(jù)透視表內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
python中的getattribute 、getattr、setattr方法詳解
這篇文章主要介紹了python中的getattribute 、getattr、setattr方法詳解,python類中默認(rèn)有一些特殊方法,這篇文章記錄一下特殊方法的功能及用法,需要的朋友可以參考下2023-11-11pyqt QGraphicsView 以鼠標(biāo)為中心進(jìn)行縮放功能實(shí)現(xiàn)
在PyQt開發(fā)中,實(shí)現(xiàn)QGraphicsView的鼠標(biāo)中心縮放功能需要注意初始化以及關(guān)鍵函數(shù)的重定義,遇到不達(dá)預(yù)期的效果時(shí),可能需要重寫所有鼠標(biāo)事件,本文記錄了解決QGraphicsView鼠標(biāo)縮放問題的過程,供開發(fā)者參考2024-10-10AI:如何訓(xùn)練機(jī)器學(xué)習(xí)的模型
這篇文章主要介紹了是如何進(jìn)行機(jī)器學(xué)習(xí)的模型的訓(xùn)練,全文邏輯清晰,簡單易懂,如果您正在學(xué)習(xí)機(jī)器學(xué)習(xí)那么可以參考下,說不定會(huì)有不一樣的收貨2021-04-04Python?獲取今天任意時(shí)刻的時(shí)間戳的方法
本文主要介紹了Python?獲取今天任意時(shí)刻的時(shí)間戳的方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧<BR>2022-06-06python利用pandas和csv包向一個(gè)csv文件寫入或追加數(shù)據(jù)
這篇文章主要給大家介紹了關(guān)于python利用pandas和csv包向一個(gè)csv文件寫入或追加數(shù)據(jù)的相關(guān)資料,我們?cè)絹碓蕉嗟氖褂胮andas進(jìn)行數(shù)據(jù)處理,有時(shí)需要向一個(gè)已經(jīng)存在的csv文件寫入數(shù)據(jù),需要的朋友可以參考下2023-07-07