This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
variable = 'Python' | |
if type(variable) in [set, int, str, dict, list, float, tuple, bool]: | |
print('It is a built-in type') | |
else: | |
print('Maybe not a built-in?') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
generator = (number for number in range(10)) | |
if type(generator) == "<class 'generator'>": | |
print('Are you crazy?') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import types | |
generator = (number for number in range(10)) | |
if isinstance(generator, types.GeneratorType): | |
print("Finally, a generator!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A function to reverse a string | |
def reverse_string(text: str, upper: bool = False) -> str: | |
reversed_text: str = text[::-1] | |
if upper: | |
return reversed_text.upper() | |
return reversed_text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def function_name(arg1: type1, opt_arg: type2 = default) -> return_type: | |
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
"""Option One"""" | |
# Load file as an ExcelFile object | |
excel = pd.ExcelFile('financial_sample.xlsx') | |
# Print out the sheet names | |
print(excel.sheet_names) # Prints out 'Sheet1' and 'Sheet2' | |
# Load the two sheets as individual DataFrames |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sas7bdat import SAS7BDAT | |
import pandas as pd | |
with SAS7BDAT('skinproduct.sas7bdat') as file: | |
sas_df = file.to_data_frame() | |
print(sas_df) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import h5py | |
filename = 'ligo_data.hdf5' | |
data = h5py.File(filename, 'r') | |
print(data.keys()) | |
# Values for each group can be accessed like this | |
print(data['meta'].value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pickle | |
with open('pickle_file.pkl', 'rb') as file: | |
data = pickle.load(file) | |
print(data) | |
num_list = [range(1000000)] | |
# How to save a Python object to a pickle file | |
with open('new_pickle.pkl', 'wb') as file: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Importing matlab files | |
import scipy.io | |
import pandas as pd | |
filename = "ja_data2.mat" | |
matlab = scipy.io.loadmat(filename) | |
print(type(matlab)) # prints out 'class <dict>' |
OlderNewer