Posts

Showing posts from October, 2019

Speech Recognition using PyAudio and SpeechRecognition Libraries

This is simple program to convert audio into text. I have used speec_recognition library to do it. import speech_recognition as sr r = sr.Recognizer() with sr.Microphone() as source:     print("Speak Anything :")     audio = r.listen(source)     try:         text = r.recognize_google(audio)         print("You said : {}".format(text))     except:         print("Sorry could not recognize what you said") Output- Speak Anything : You said : internet is required to access the Google API if there is no internet you will not be able to convert voice into text to install SpeechRecognition- https://pypi.org/project/SpeechRecognition/ one of the dependencies is PyAudio which is not supported after 3.6. For python verison 3.6+ one needs to download wheel (  https://python101.pythonlibrary.org/chapter39_wheels.html )  and install PyAudio separately. https://sta...

Geo-Spatial plots in python

Image
Python library Geopandas used for plotting geo-spatial data- import geopandas world = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres')) world.plot() <matplotlib.axes._subplots.AxesSubplot at 0x2fd60a9ecf8>

Date TIme in Python for data scientists

Image
python date datatype- datetime pandas date datatype- Timestamp 1) creating pandas datframe with string dates value ## datetime date_data= pd.DataFrame(np.random.randint(10,100, (4,3)), columns=['A','B','C']) dates= ['2 june 2013', '5 Aug 2015', '2015-07-09', '7/12/2014'] date_data.index= dates A B C 2 june 2013 52 61 89 5 Aug 2015 21 69 89 2015-07-09 88 23 13 7/12/2014 43 39 21 creating string into pandas datetime format- date_data.index= pd.to_datetime(date_data.index) date_data A B C 2013-06-02 59 93 77 2015-08-05 33 15 28 2015-07-09 63 19 25 2014-07-12 29 36 92 2) Time difference in pandas- ...

Pivot table in Python

create a pandas dataframe- import numpy as np import pandas as pd cars_data= pd.DataFrame([[10,5,3,'X'], [1,2,3,'Y'],[3,4,5,'X'], [10,5,3,'X'], [1,2,3,'Y'],[3,4,5,'X']], columns=['A','B','C','Type']) cars_data A B C Type 0 10 5 3 X 1 1 2 3 Y 2 3 4 5 X 3 10 5 3 X 4 1 2 3 Y 5 3 4 5 X create pivot_table a method in pandas # using pivot to convert rows to column pivot_car= cars_data.pivot_table(columns=['Type', 'A'], aggfunc= [np.mean, np.amax]) mean amax Type A B X 3 4 4 10 5 5 ...