Skip to content

Instantly share code, notes, and snippets.

View Ze1598's full-sized avatar

José Fernando Costa Ze1598

  • Porto, Portugal
View GitHub Profile
@Ze1598
Ze1598 / transcribe_video_audio.py
Created January 28, 2021 11:01
Transcribe video audio using Azure Cognitive Services
import azure.cognitiveservices.speech as speechsdk
import time
import pickle
subscription_key = "your_key"
speech_region = "your_region"
file_name = "your_audio.wav"
# Authenticate
speech_config = speechsdk.SpeechConfig(subscription_key, speech_region)
# Set up the file as the audio source
@Ze1598
Ze1598 / cogn_serv_auth.py
Created January 28, 2021 10:58
Authenticate into Azure Cognitive Services through the Python SDK
import azure.cognitiveservices.speech as speechsdk
subscription_key = "your_key"
speech_region = "your_region"
speech_config = speechsdk.SpeechConfig(subscription_key, speech_region)
@Ze1598
Ze1598 / extract_audio.py
Last active January 28, 2021 11:25
Extract audio from video
from moviepy.editor import VideoFileClip
video = VideoFileClip("your_video.mp4")
audio = video.audio
audio.write_audiofile("audio_only.wav")
@Ze1598
Ze1598 / prog_languages.py
Last active January 24, 2021 21:19
Python Data Analysis Part 4: Programming Languages
import pandas as pd
from os import getcwd, path
import plotly.express as px
import plotly.offline as pyo
pyo.init_notebook_mode()
path_to_data = path.join(getcwd(), "data", "survey_results_public.csv")
data = pd.read_csv(path_to_data)
data = data[["LanguageWorkedWith"]]
@Ze1598
Ze1598 / education.py
Last active January 24, 2021 18:59
Python Data Analysis Part 3: Education of Respondents
import pandas as pd
from os import getcwd, path
import plotly.express as px
import plotly.offline as pyo
pyo.init_notebook_mode()
path_to_data = path.join(getcwd(), "data", "survey_results_public.csv")
data = pd.read_csv(path_to_data)
data = data[["EdLevel"]]
@Ze1598
Ze1598 / compensation.py
Last active January 24, 2021 17:39
Python Data Analysis Part 2: Annual Compensation
import pandas as pd
from os import getcwd, path
import plotly.express as px
import plotly.offline as pyo
pyo.init_notebook_mode()
path_to_data = path.join(getcwd(), "data", "survey_results_public.csv")
data = pd.read_csv(path_to_data)
data = data[["ConvertedComp"]]
@Ze1598
Ze1598 / age.py
Created January 24, 2021 15:26
Python Data Analysis Part 1: Age of Respondents
import pandas as pd
from os import getcwd, path
import plotly.express as px
import plotly.offline as pyo
pyo.init_notebook_mode()
path_to_data = path.join(getcwd(), "data", "survey_results_public.csv")
data = pd.read_csv(path_to_data)
data = data[["Age"]]
@Ze1598
Ze1598 / custom_mask.py
Created December 6, 2020 16:54
Create a custom shape mask with Python & Pillow
from PIL import Image
# Create a blank grey image
wip_img = Image.new("RGBA", (550, 450), "#f2f2f2")
# Load the santa hat
santa_hat = Image.open("santa_hat.png")
# At first this is just a black rectangle of the same size as the hat
shadow = Image.new("RGBA", santa_hat.size, color="black")
# Coordinates at which to draw the hat and shadow
@Ze1598
Ze1598 / custom_sort_order.py
Created November 1, 2020 21:45
Create a custom sort for a pandas DataFrame column: months example
import pandas as pd
import numpy as np
def generate_random_dates(num_dates: int) -> np.array:
"""Generate a 1D array of `num_dates` random dates.
"""
start_date = "2020-01-01"
# Generate all days for 2020
available_dates = [np.datetime64(start_date) + days for days in range(365)]
# Get `num_dates` random dates from 2020
@Ze1598
Ze1598 / fcc_gbc_complete.py
Last active October 21, 2020 19:27
freeCodeCamp grouped bar chart visualization: complete script
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
# Load the CSV (load date data as proper date types)
df = pd.read_csv("page_views.csv")
df["date"] = pd.to_datetime(df["date"])
# Sort the DF from oldest to most recent recordings
df.sort_values(by="date", inplace=True)
# Use the column of dates as the DF's index