petercour
Posted on July 24, 2019
In Python there's a module that helps you parse data. Data can be in many forms (files, tables, excel, sql, json). There exists so many data sources for historic reasons.
That module to work with data is named the pandas module.
You may know you can use the Pandas module for data analysis. But did you know there are many ways to read data?
pd.read_csv(filename)
pd.read_table(filename)
pd.read_excel(filename)
pd.read_sql(query, connection_object)
pd.read_json(json_string)
pd.read_html(url)
pd.read_clipboard()
Yes, you can read data from many sources. These methods allow you to quickly grab your data
#!/usr/bin/python3
import pandas as pd
data = pd.read_csv('yourfile.csv', header=None)
If you are using MySQL as source
#!/usr/bin/python3
db = MySQLDatabase(DATABASE_HOST, DATABASE_USER, DATABASE_PASSWORD, DATABASE_NAME)
db_work_view = db.get_work_view()
connection = db_work_view._db_connection
df_people = pd.read_sql('select * from people', connection)
Reading an excel file
df = pd.read_excel('File.xlsx', sheetname='Sheet1')
Well you get the idea. Pandas allows you to quickly fetch data from different data sources. It includes most of the existing data sources.
Related links:
💖 💪 🙅 🚩
petercour
Posted on July 24, 2019
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
datascience Seaborn Plot Selection Made Easy: How to Visualize Your Data Effectively
November 29, 2024