用Python实现数据透视表、音频文件格式转换

用Python实现数据透视表、音频文件格式转换

1.用Python实现数据透视表

import pandas as pd


if __name__ == '__main__':
    # df = pd.read_excel('广告-资源位变现效率监测看板-1.xlsx', sheet_name='各业务在该资源位的明细数据')
    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['业务类型'] == '品牌广告']
    total = df['库存'].sum()
    print(total)

2.用Python实现音频文件格式转换

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; ")

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

穿越前列线打造非凡yt

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值