Pandas CustomBusinessHour reduced performance

Issue I need to reduce the performance of the following operation : st = time.time() bh = CustomBusinessHour(start=’00:00′, end=’23:00′) bdates = pd.date_range(start=’2024-01-01 00:00:00′, end=’2024-12-31 23:00:00′, freq=bh, name=’ts’, closed=None) print_statistics(f'{bdates}’, ‘filter_bp()’, ‘utils.py’, time.time() – st) which gives has the following output

Continue reading

Python: Loop over datetimeindex based on different periods

Issue I have a DataFrame and I am trying to loop over the datetmeindex based on different frequencies: data = [[99330,12,122],[1123,1230,1287],[123,101,812739],[1143,12301230,252],[234,342,4546],[2445,3453,3457],[7897,8657,5675], [46,5675,453],[76,484,3735], [363,93,4568], [385,568,367], [458,846,4847], [574,45747,658468], [57457,46534,4675]] df1 = pd.DataFrame(data, index=[‘2022-01-01’, ‘2022-01-02’, ‘2022-01-03’, ‘2022-01-04’, ‘2022-01-05’, ‘2022-01-06’, ‘2022-01-07’, ‘2022-01-08’, ‘2022-01-09’, ‘2022-01-10’,

Continue reading

Convert columns in (.csv) file to (.json) column array in Python

Issue I am trying to convert a (.csv) file to a .json file which is stored in the form of a column array. The input (.csv) file is: This is my desired result: { "wavelength":[0.033962528,0.035974933,0.03801894,0.039994474,0.041975898,0.043954162], "n":[0.842171,0.83072,0.819753,0.809997,0.802291,0.797737], "k":[0.090738197,0.10934279,0.13025372,0.15338756,0.17980019,0.20882868], "alpha":[33573761.42,38194428.97,43052660.58,48194781.27,53826980.05,59703529.05], "absorption_length":[2.98e-8,2.62e-8,2.32e-8,2.07e-8,1.86e-8,1.67e-8] }

Continue reading

IF + AND Statements

Issue I have a ‘Current Result’ in the form of a data frame in Python (depicting in Excel as an illustration). I’d like to add a column that classifies whether a row is a ‘PRIME’ or an ‘ALT’ designation. The

Continue reading

Pandas Dataframe – Adding Else?

Issue I want to generate Test Data for my Bayesian Network. This is my current Code: data = np.random.randint(2, size=(5, 6)) columns = [‘p_1’, ‘p_2’, ‘OP1’, ‘OP2’, ‘OP3’, ‘OP4’] df = pd.DataFrame(data=data, columns=columns) df.loc[(df[‘p_1’] == 1) & (df[‘p_2’] == 1),

Continue reading

How to split DF by dates based on another DF

Issue I have two DataFrames (df1, df2), both with a DateTime index type: print(type(df1.index)) => pandas.core.indexes.datetimes.DatetimeIndex print(type(df2.index)) => pandas.core.indexes.datetimes.DatetimeIndex They look like: df1: Sample Date Value_df1 1992-01-02 430.0 1992-01-03 436.0 1992-01-04 439.0 1992-01-05 432.0 1992-01-06 427.0 1992-01-07 427.0 1992-01-08 425.0

Continue reading

Combine two columns with same name pandas

Issue I have a list from an API response: list = [[[[‘3200’, ‘house_number’],[‘northline ave’, ‘road’],[‘ste 360’, ‘unit’],[‘greensboro’, ‘city’],[‘27408’, ‘postcode’],[‘7611’, ‘city’],[‘nc’, ‘state’],[‘us’, ‘country’]]]] As you can see I have column road twice, I want to combine two road columns into one.

Continue reading

pandas dataframe to html – border not accurate

Issue I have a dataframe like as below test_id,status,total,cnt_days,age 1,passed,234%,3,21 2,passed,54%,5,29 11,failed,21%,4,35 15,failed,20%.21,6,57 51,passed,23%,21,80 75,failed,12%,32,43 df1 = pd.read_clipboard(sep=’,’) My objective is to a) Have dark border lines between rows and column using black color b) Use Green color for header

Continue reading

Map different column values with website context

Issue I have a dataframe like this: df1 = pd.DataFrame({ "index": ["EXEC sp_delete_job", "exec sp_add_job", "something else","exec sp_add_jobserver"], "index1": ["NaN", "NaN", "NaN", "exec sp_delete_job"], "index2": ["EXEC sp_droplogin", "EXEC sp_delete_job", "NaN", "something else"], "index3": ["EXEC sp_droplogin", "EXEC sp_delete_job", "exec sp_add_job", "exec

Continue reading