Member-only story
8 Essential Python Techniques for Data Engineers and Analysts (with code samples)
These are the Python code snippets I re-use the most
Even the most experienced coders google stuff.
I re-google simple lines of code that I use all the time just as a quick reminder of syntax. In that sense, I’m really writing this article for myself. These are the most common pieces of Python code that I re-use over and over again as a Data Generalist.
(All the below examples are done using Python 3.6 or later)
Querying Data from a DB into a Pandas DataFrame or a CSV file
When SQL isn’t sufficient for an analysis or a complex data transformation, Python is probably the answer. But before you can wrangle any data, you have to get the data into memory so you can do stuff with it. Using PYODBC if you’re database is on MS SQL Server or PSYCOPG2 if you’re on Postgres, you can write queries and pull data easily using Python. From there it’s just a matter of getting your data into a format that’s easy to work with. For this I like Pandas. Getting the query data into Pandas is as simple as converting the list to a CSV and then using the pandas…