open(file_name, 'r') |
open the file
|
file.read() |
read the file
|
file.close() |
close the file
|
file.closed() |
check if the file is closed
|
with open(file_name) as file : |
open the file
|
file.read() |
read the file
|
|
file.readline()
|
read line by line
|
import numpy as np |
import numpy
|
np.loadtxt(file_name, delimiter= ' ') |
importing the file
|
skiprows=1 |
argument to skip a specific row
|
usecols=[0, 2] |
argument to only show specific columns
|
|
`dtype = str'
|
argument to import the data as string
|
import numpy as np |
import numpy
|
np.recfromcsv(file, delimiter=",", names=True, dtype=None) |
open the file
|
np.genfromtxt(file, delimiter=',', names=True, dtype=None) |
open the file
|
import pandas as pd |
importing pandas
|
df = pd.read_stata('disarea.dta') |
reading the stata file
|
import pandas as pd |
import pandas
|
pd.read_csv(file) |
open csv file
|
nrows=5 |
argument for the number of rows to load
|
header=None |
argument for no header
|
sep='\t' |
argument to set delimiter
|
comment='#' |
argument takes characters that comments occur after in the file
|
na_values='Nothing' |
argument to recognize a string as a NaN Value
|
import pickle |
import the library
|
with open(file_name, 'rb') as file : |
open file
|
pickle.load(file) |
read file
|
import pandas as pd |
importing pandas
|
pd.ExcelFile(file) |
opening the file
|
xl.sheet_names |
exporting the sheet names
|
xl.parse(sheet_name/index) |
loading a sheet to a dataframe
|
skiprows=[index] |
skipping a specific row
|
names=[List of Names] |
naming the sheet's columns
|
usecols=[0,] |
parse spesific columns
|
from sas7bdat import SAS7BDAT |
importing sas7bdat library
|
import pandas as pd |
importing pandas
|
with SAS7BDAT('file_name') as file: |
opening the file
|
file.to_data_frame() |
loading the file as dataframe
|
import numpy as np |
import numpy
|
import h5py |
importing the h5py library
|
h5py.File(file, 'r') |
reading the file
|
import scipy.io |
importing scipy.io
|
cipy.io.loadmat('file_name') |
reading the file
|
import pandas as pd |
importing pandas
|
from sqlalchemy import create_engine |
importing the necessary library
|
engine = create_engine('databasetype:///name.databasetype') |
creating an engine
|
con = engine.connect() |
connecting to the engine
|
rs = con.execute('SELECT * FROM Album') |
performe query
|
df = pd.DataFrame(rs.fetchall()) |
save as a dataframe
|
df.columns = rs.keys |
set columns names
|
con.close() |
close the connection
|
engine = create_engine('databasetype:///name.databasetype') |
creating an engine
|
with engine.connect() as con: |
connecting to the engine
|
rs = con.execute('sql code') |
performe query
|
df = pd.DataFrame(rs.fetchmany(size=3)) |
load a number of rows as a dataframe
|
engine = create_engine('databasetype:///name.databasetype') |
creating an engine
|
df = pd.read_sql_query('SQL code', engine) |
performe query
|
No comments yet.
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.