Skip to content

Instantly share code, notes, and snippets.

@akrisanov
Last active July 21, 2018 18:47
Show Gist options
  • Save akrisanov/1f0ff3ce6e20bf8909c47e25387c24c3 to your computer and use it in GitHub Desktop.
Save akrisanov/1f0ff3ce6e20bf8909c47e25387c24c3 to your computer and use it in GitHub Desktop.
DataCamp: Importing Data in Python (Part 1)
import numpy
# Print the keys of the MATLAB dictionary
print(mat.keys())
# Print the type of the value corresponding to the key 'CYratioCyt'
print(type(mat['CYratioCyt']))
# Print the shape of the value corresponding to the key 'CYratioCyt'
print(numpy.shape(mat['CYratioCyt']))
# Subset the array and plot it
data = mat['CYratioCyt'][25, 5:]
fig = plt.figure()
plt.plot(data)
plt.xlabel('time (min.)')
plt.ylabel('normalized fluorescence (measure of expression)')
plt.show()
from sqlalchemy import create_engine
import pandas as pd
engine = create_engine('sqlite:///Chinook.sqlite')
# Open engine in context manager
# Perform query and save results to DataFrame: df
with engine.connect() as con:
rs = con.execute('SELECT LastName, Title FROM Employee')
df = pd.DataFrame(rs.fetchmany(size=3))
df.columns = rs.keys()
# Print the length of the DataFrame df
print(len(df))
# Print the head of the DataFrame df
print(df.head())
# Import packages
from sqlalchemy import create_engine
import pandas as pd
# Create engine: engine
engine = create_engine('sqlite:///Chinook.sqlite')
# Execute query and store records in DataFrame: df
df = pd.read_sql_query('SELECT * FROM Album', engine)
# Print head of DataFrame
print(df.head())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment