What do you want to save?
Add Code snippet
New code examples
-
Python 2022-01-26 03:00:13
how to only print final iteration of a for loop pyhton
prices = [10, 20, 30] total = 0 for price in prices: total += price #print(f'total: {total}') will give all iterations in order print(f'total: {total}') #make sure to print outside of loop for #only final iteration to print Add solution -
Python 2022-01-22 00:26:40
cartecian to spherical python
#this is just an easy way to do this , #not optimised for better scientific calculations import math as m def cartesian_to_spherical(x,y,z): r = m.sqrt((x**2) +(y**2)+(z**2)) theta = m.acos(z/r) phi = m.atan(y/x) print(f'r = {r},\nθ... Add solution -
Python 2021-11-12 20:13:24
how to read multiple worksheet from a single workbook in column in python
import pandas as pd def read_excel_sheets(xls_path): """Read all sheets of an Excel workbook and return a single DataFrame""" print(f'Loading {xls_path} into pandas') xl = pd.ExcelFile(xls_path) df = pd.DataF... Add solution -
Python 2021-11-07 13:47:15
sum axis in python
import numpy as np array1 = np.array( [[1, 2], [3, 4], [5, 6]]) total_0_axis = np.sum(array1, axis=0) print(f'Sum of elements at 0-axis is {total_0_axis}') total_1_axis = np.sum(array1, axis=1) print(f'Sum of elements at 1-axis is {total_... Add solution -
Python 2021-11-06 02:11:09
python - multiprocessing
import time from multiprocessing import Process # My functions (threads) def my_func_1():... def my_func_2():... # Single calculation start = time.time() my_func_1() my_func_2() print(f'Single thread total time: {time.time() - start}') # Processes pr... Add solution