목록Note (472)
Note
How to limit the number of items printed in output of numpy array? np.set_printoptions(threshold=6) a = np.arange(15) a # output array([ 0, 1, 2, ..., 12, 13, 14])
How to convert year-month string to dates corresponding to the 4th day of the month? import pandas as pd # Input ser = pd.Series(['Jan 2010', 'Feb 2011', 'Mar 2012']) # 1 from dateutil.parser import parse # Parse the date ser_ts = ser.map(lambda x: parse(x)) # Construct date string with date as 4 ser_datestr = ser_ts.dt.year.astype('str') + '-' + ser_ts.dt.month.astype('str') + '-' + '04' # Form..
How to pretty print a numpy array by suppressing the scientific notation (like 1e10)? # Reset printoptions to default np.set_printoptions(suppress=False) # Create the random array np.random.seed(100) rand_arr = np.random.random([3,3])/1e3 # output array([[ 5.434049e-04, 2.783694e-04, 4.245176e-04], [ 8.447761e-04, 4.718856e-06, 1.215691e-04], [ 6.707491e-04, 8.258528e-04, 1.367066e-04]]) np.set_..
How to get the day of month, week number, day of year and day of week from a series of date strings? # Input ser = pd.Series(['01 Jan 2010', '02-02-2011', '20120303', '2013/04/04', '2014-05-05', '2015-06-06T12:20']) # Solution from dateutil.parser import parse ser_ts = ser.map(lambda x: parse(x)) # day of month print("Date: ", ser_ts.dt.day.tolist()) # week number print("Week number: ", ser_ts.d..
How to print only 3 decimal places in python numpy array? # Input rand_arr = np.random.random((5,3)) # Create the random array rand_arr = np.random.random([5,3]) # Limit to 3 decimal places np.set_printoptions(precision=3) rand_arr[:4] # output array([[ 0.443, 0.109, 0.97 ], [ 0.388, 0.447, 0.191], [ 0.891, 0.474, 0.212], [ 0.609, 0.518, 0.403]])