如何使用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='庫(kù)存底表')
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['庫(kù)存'].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)文章希望大家以后多多支持腳本之家!
- 利用Python小工具實(shí)現(xiàn)3秒鐘將視頻轉(zhuǎn)換為音頻
- Python使用pydub模塊轉(zhuǎn)換音頻格式以及對(duì)音頻進(jìn)行剪輯
- Python?如何實(shí)現(xiàn)批量轉(zhuǎn)換視頻音頻的采樣率
- Python實(shí)現(xiàn)將mp3音頻格式轉(zhuǎn)換為wav格式
- Python實(shí)現(xiàn)視頻轉(zhuǎn)換為音頻的方法詳解
- Python腳本實(shí)現(xiàn)音頻和視頻格式轉(zhuǎn)換
- Python使用FFmpeg實(shí)現(xiàn)高效音頻格式轉(zhuǎn)換工具
- 使用python中Pydub進(jìn)行音頻格式轉(zhuǎn)換
相關(guān)文章
基于opencv實(shí)現(xiàn)簡(jiǎn)單畫(huà)板功能
這篇文章主要為大家詳細(xì)介紹了基于opencv實(shí)現(xiàn)簡(jiǎn)單畫(huà)板功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-08-08
Django+Vue實(shí)現(xiàn)文件上傳下載的項(xiàng)目實(shí)踐
本文主要介紹了Django+Vue實(shí)現(xiàn)文件上傳下載的項(xiàng)目實(shí)踐,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-06-06
python之no module named xxxx以及虛擬環(huán)境配置過(guò)程
在Python開(kāi)發(fā)過(guò)程中,經(jīng)常會(huì)遇到環(huán)境配置和包管理的問(wèn)題,主要原因包括未安裝所需包或使用虛擬環(huán)境導(dǎo)致的,通過(guò)pip install命令安裝缺失的包是解決問(wèn)題的一種方式,此外,使用虛擬環(huán)境,例如PyCharm支持的Virtualenv,可以為每個(gè)項(xiàng)目創(chuàng)建獨(dú)立的運(yùn)行環(huán)境2024-10-10
python 實(shí)現(xiàn)創(chuàng)建文件夾和創(chuàng)建日志文件的方法
這篇文章主要介紹了python 實(shí)現(xiàn)創(chuàng)建文件夾和創(chuàng)建日志文件的方法,文中給大家介紹了python 讀寫(xiě)創(chuàng)建文件文件夾的方法 ,需要的朋友可以參考下2019-07-07
一文帶你詳解Python中sys.executable函數(shù)的作用
sys.executable函數(shù)是用來(lái)獲取當(dāng)前Python解釋器的完整路徑的,本文主要介紹了一文帶你詳解Python中sys.executable函數(shù)的作用,具有一定的參考價(jià)值,感興趣的可以了解一下2024-03-03
淺談Python numpy創(chuàng)建空數(shù)組的問(wèn)題
今天遇到一個(gè)小小的問(wèn)題,是關(guān)于numpy創(chuàng)建空數(shù)組,今天特地整理了這篇文章,文中作出了非常詳細(xì)的介紹,對(duì)正在學(xué)習(xí)python的小伙伴們有很好的幫助,需要的朋友可以參考下2021-05-05
Python3使用Selenium獲取session和token方法詳解
這篇文章主要介紹了Python3使用Selenium獲取session和token方法詳解,需要的朋友可以參考下2021-02-02
python用dataframe將csv中的0值數(shù)據(jù)轉(zhuǎn)化為nan缺失值字樣
本文主要介紹了python用dataframe將csv中的0值數(shù)據(jù)轉(zhuǎn)化為nan缺失值字樣,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-08-08

