Use a dictionary to save all the order data after reading the input file - c#-4.0

OrderID=1211, OrderName=’Alice’, OrderDate= ‘15-10-2019’
OrderID=1211, ItemID=1, ItemName=’Laptop’, ItemCompany=’Dell’, ItemPrice=’40000’
OrderID=1211, ItemID=2, ItemName=’Mouse’, ItemCompany=’Logitech’, ItemPrice=’5000’
OrderID=121, ItemID=3, ItemName= ‘Keyboard’, ItemCompany=’LogiTech’, ItemPrice=’12000’
OrderID=1211, ItemID=4, ItemName= ‘Monitor’, ItemCompany=’Samsung’, ItemPrice=’49000’
OrderID=4322, OrderName=’Ben’, OrderDate= ‘1-10-2019’
OrderID=4322, ItemID=1, ItemName=’Laptop’, ItemCompany=’Microsoft’, ItemPrice=’40000’
OrderID=4322, ItemID=2, ItemName= ‘Keyboard’, ItemCompany=’Microsoft’, ItemPrice=’12000’
OrderID=4322, ItemID=3, ItemName=’Mouse’, ItemCompany=’Logitech’, ItemPrice=’5000’
OrderID=4322, ItemID=4, ItemName= ‘Monitor’, ItemCompany=’Dell’, ItemPrice=’49000’
Output to be in: Item Company, Total Number of Items Ordered, Total Sales
Ex: Item Company- Dell, Total Number Items ordered-2 (Instances of Dell), Total Sales- 89000 (sum of 2 instances price).
Please help me in writing the code to solve this problem. Thank you.

Related

Failing to use sumproduct on date ranges with multiple conditions [Python]

From replacement data table (below on the image), I am trying to incorporate the solbox product replace in time series data format(above on the image). I need to extract out the number of consumers per day from the information.
What I need to find out:
On a specific date, which number of solbox product was active
On a specific date, which number of solbox product (which was a consumer) was active
I have used this line of code in excel but cannot implement this on python properly.
=SUMPRODUCT((Record_Solbox_Replacement!$O$2:$O$1367 = "consumer") * (A475>=Record_Solbox_Replacement!$L$2:$L$1367)*(A475<Record_Solbox_Replacement!$M$2:$M$1367))
I tried in python -
timebase_df['date'] = pd.date_range(start = replace_table_df['solbox_started'].min(), end = replace_table_df['solbox_started'].max(), freq = frequency)
timebase_df['date_unix'] = timebase_df['date'].astype(np.int64) // 10**9
timebase_df['no_of_solboxes'] = ((timebase_df['date_unix']>=replace_table_df['started'].to_numpy()) & (timebase_df['date_unix'] < replace_table_df['ended'].to_numpy() & replace_table_df['customer_type'] == 'customer']))
ERROR:
~\Anaconda3\Anaconda4\lib\site-packages\pandas\core\ops\array_ops.py in comparison_op(left, right, op)
232 # The ambiguous case is object-dtype. See GH#27803
233 if len(lvalues) != len(rvalues):
--> 234 raise ValueError("Lengths must match to compare")
235
236 if should_extension_dispatch(lvalues, rvalues):
ValueError: Lengths must match to compare
Can someone help me please? I can explain in comment section if I have missed something.

Calculating number of times each IAT was called from PE

I am trying to calculate the number of times each IAT-import address table was called by a PE. It is like this:
counter=0
for entry in file.DIRECTORY_ENTRY_IMPORT:
print (entry.dll)
for imp in entry.imports:
print ('\t', hex(imp.address), imp.name)
counter=counter+1
print(entry.dll,":",counter)
The output is somewhat like this:
b'KERNEL32.dll'
0x180006000 b'GetProcAddress'
0x180006008 b'LoadLibraryA'
0x180006010 b'IsProcessorFeaturePresent'
0x180006018 b'GetStartupInfoW'
0x180006020 b'SetUnhandledExceptionFilter'
0x180006028 b'UnhandledExceptionFilter'
0x180006030 b'IsDebuggerPresent'
0x180006038 b'RtlVirtualUnwind'
0x180006040 b'RtlLookupFunctionEntry'
0x180006048 b'RtlCaptureContext'
0x180006050 b'InitializeSListHead'
0x180006058 b'DisableThreadLibraryCalls'
0x180006060 b'GetSystemTimeAsFileTime'
0x180006068 b'GetCurrentThreadId'
0x180006070 b'GetCurrentProcessId'
0x180006078 b'QueryPerformanceCounter'
0x180006080 b'GetModuleHandleW'
b'KERNEL32.dll' : 17
b'MSVCP140.dll'
0x180006090 b'?_Xout_of_range#std##YAXPEBD#Z'
0x180006098 b'?_Xlength_error#std##YAXPEBD#Z'
0x1800060a0 b'?_Xbad_alloc#std##YAXXZ'
b'MSVCP140.dll' : 20
b'VCRUNTIME140.dll'
0x1800060b0 b'_purecall'
0x1800060b8 b'__std_terminate'
0x1800060c0 b'memmove'
0x1800060c8 b'_CxxThrowException'
0x1800060d0 b'__std_type_info_destroy_list'
0x1800060d8 b'__RTDynamicCast'
0x1800060e0 b'memcpy'
0x1800060e8 b'__C_specific_handler'
0x1800060f0 b'__std_exception_copy'
0x1800060f8 b'__std_exception_destroy'
0x180006100 b'__CxxFrameHandler3'
0x180006108 b'memset'
b'VCRUNTIME140.dll' : 32
But it should count each entry individually. For example, MSVCP140.dll should be counted as '3' and not '20'. Any help would be gladly appreciated.

Resampling Time Series Data (Pandas Python 3)

Trying to convert data at daily frequency to weekly frequency.
In:
weeklyaaapl = pd.DataFrame()
weeklyaapl['Open'] = aapl.Open.resample('W').iloc[0]
#here I am trying to take the first value of the aapl.Open,
#that falls within the week.
Out:
ValueError: .resample() is now a deferred operation
use .resample(...).mean() instead of .resample(...)
I want the true open (the first open that prints for the week) (the open of the first day in that week).
It instead wants me to take the mean of the daily open values for a given week using .mean(), which is not the information I need.
Can't seem to interpret the error, documentation isn't helping either.
I think you need.
aapl.resample('W').first()
Output:
Open High Low Close Volume
Date
2010-01-10 30.49 30.64 30.34 30.57 123432050
2010-01-17 30.40 30.43 29.78 30.02 115557365
2010-01-24 29.76 30.74 29.61 30.72 182501620
2010-01-31 28.93 29.24 28.60 29.01 266424802
2010-02-07 27.48 28.00 27.33 27.82 187468421

If Cell Starts with String from a List Return Number

What I am looking for is either a formula or Macro/code that will allow me to do the following:
I have a list of the beginning of Postcodes, for example, "AB31, AB32, AB33, AB34", I need something that will return a value of 313 if the start of a cell contains a value from this list I have, and a value of 74 if it does not start with a value from that list.
Now the list is quite long, theres probably 100+ values in there. If there weren't so many values in the list I could use something like
=IF(LEFT(K1,4)="AB51","313","72")
The Postcode will be in the K column, and the full list I need it to search through is
AB31
AB32
AB33
AB34
AB35
AB36
AB37
AB38
AB40
AB41
AB42
AB43
AB44
AB45
AB46
AB47
AB48
AB49
AB50
AB51
AB52
AB53
AB54
AB55
AB56
BT
GY
HS
IM
IV1
IV2
IV3
IV4
IV5
IV6
IV7
IV8
IV9
IV10
IV11
IV12
IV13
IV14
IV15
IV16
IV17
IV18
IV19
IV20
IV21
IV22
IV23
IV24
IV25
IV26
IV27
IV28
IV30
IV31
IV32
IV36
IV40
IV41
IV42
IV43
IV44
IV45
IV46
IV47
IV48
IV49
IV51
IV52
IV53
IV54
IV55
IV56
IV63
J3
KA27
KA28
KW1
KW2
KW3
KW4
KW5
KW6
KW7
KW8
KW9
KW10
KW11
KW12
KW13
KW14
KW15
KW16
KW17
PA20
PA21
PA22
PA23
PA24
PA25
PA26
PA27
PA28
PA29
PA30
PA31
PA32
PA33
PA34
PA35
PA36
PA37
PA38
PA41
PA42
PA43
PA44
PA45
PA46
PA47
PA48
PA49
PA60
PA61
PA62
PA63
PA64
PA65
PA66
PA67
PA68
PA69
PA70
PA71
PA72
PA73
PA74
PA75
PA76
PA77
PA78
PH4
PH5
PH6
PH7
PH8
PH9
PH10
PH11
PH12
PH13
PH14
PH15
PH16
PH17
PH18
PH19
PH20
PH21
PH22
PH23
PH24
PH25
PH26
PH27
PH28
PH29
PH30
PH31
PH32
PH33
PH34
PH35
PH36
PH37
PH38
PH39
PH40
PH41
PH42
PH43
PH44
PH49
PH50
TR21
TR22
TR23
TR24
TR25
ZE
So if any Postcode in column K begins with any of those values, I would like the number 313 returning, if not the number 72 returning.
Any help would be much appreciated.
Thanks!
You should give example on how your sheets look like or else it is very difficult to answer.
what I will do
Put the list on a Column
Use combination of IF and Vlookup to loop through the list.
=IF(VLOOKUP(LEFT(K1, 4),A:A,1,0)=LEFT(K1, 4),313,72)
Column E Column F Column G
Post Code Result Formula
AB31456 313 =IF(VLOOKUP(LEFT(E2,4),A:A,1,0)=LEFT(E2,4),313,72)
KZ12398 72 =IF(VLOOKUP(LEFT(E2,4),A:A,1,0)=LEFT(E2,4),313,72)

Use matlab to search excel data file for time range and copy data into variable

In my excel file I have a time column in 12 hr clock time and a bunch of data columns. I have pasted a snippet of it in this post as a code since i cant attach a file. I am trying to build a gui that will take an input from the user like so:
start time: 7:29:32 AM
End time: 7:29:51 AM
Then do the following:
calculate the time that has passed in seconds (should be just a row count, data is gathered once a second)
copy the data in the time range from the "Data 3" column in to a variable perform other calculations on the data copied as needed
I am having some trouble figuring out what to do to search the time data and find its location since it imports as text with xlsread. any ideas?
The data looks like this:
Time Data 1 Data 2 Data 3 Data 4 Data 5
7:29:25 AM 0.878556385 0.388400561 0.076890401 0.93335277 0.884750618
7:29:26 AM 0.695838393 0.712762566 0.014814069 0.81264949 0.450303694
7:29:27 AM 0.250846937 0.508617941 0.24802015 0.722457624 0.47119616
7:29:28 AM 0.206189924 0.82970364 0.819163787 0.060932817 0.73455323
7:29:29 AM 0.161844331 0.768214077 0.154097877 0.988201094 0.951520263
7:29:30 AM 0.704242494 0.371877481 0.944482485 0.79207359 0.57390951
7:29:31 AM 0.072028024 0.120263127 0.577396985 0.694153791 0.341824004
7:29:32 AM 0.241817775 0.32573323 0.484644494 0.377938298 0.090122672
7:29:33 AM 0.500962945 0.540808907 0.582958676 0.043377373 0.041274613
7:29:34 AM 0.087742217 0.596508236 0.020250297 0.926901109 0.45960323
7:29:35 AM 0.268222071 0.291034947 0.598887588 0.575571111 0.136424853
7:29:36 AM 0.42880255 0.349597405 0.936733938 0.232128788 0.555528823
7:29:37 AM 0.380425154 0.162002488 0.208550466 0.776866494 0.79340504
7:29:38 AM 0.727940393 0.622546124 0.716007768 0.660480612 0.02463804
7:29:39 AM 0.582772435 0.713406643 0.306544291 0.225257421 0.043552277
7:29:40 AM 0.371156954 0.163821476 0.780515577 0.032460418 0.356949005
7:29:42 AM 0.484167263 0.377878242 0.044189636 0.718147456 0.603177625
7:29:43 AM 0.294017186 0.463360581 0.962296024 0.504029061 0.183131098
7:29:44 AM 0.95635086 0.367849494 0.362230918 0.984421096 0.41587606
7:29:45 AM 0.198645523 0.754955312 0.280338922 0.79706146 0.730373691
7:29:46 AM 0.058483961 0.46774544 0.86783339 0.147418954 0.941713252
7:29:47 AM 0.411193343 0.340857813 0.162066261 0.943124515 0.722124394
7:29:48 AM 0.389312994 0.129281042 0.732723258 0.803458815 0.045824426
7:29:49 AM 0.549633038 0.73956852 0.542532728 0.618321989 0.358525184
7:29:50 AM 0.269925317 0.501399748 0.938234302 0.997577871 0.318813506
7:29:51 AM 0.798825842 0.24038537 0.958224157 0.660124357 0.07469288
7:29:52 AM 0.963581196 0.390150081 0.077448543 0.294604314 0.903519943
7:29:53 AM 0.890540963 0.50284339 0.229976565 0.664538451 0.926438543
7:29:54 AM 0.46951573 0.192568637 0.506730373 0.060557482 0.922857391
7:29:55 AM 0.56552394 0.952136998 0.739438663 0.107518765 0.911045415
7:29:56 AM 0.433149875 0.957190309 0.475811126 0.855705733 0.942255155
and this is the code I am using:
[Data,Text] = xlsread('C:\Users\data.xlsx',2);
IndexStart=strmatch('7:29:29 AM',Text,'exact'); %start time
IndexEnd=strmatch('2:30:29 PM',Text,'exact'); %end time
seconds = IndexEnd-IndexStart;
TestData = Data([IndexStart: IndexEnd],:);
You probably need to:
Use strfind to find the relevant string in the data imported
Use datenum to convert the date to serial date numbers, to be able to calculate the elapsed time between the two points.
It would help if you posted your code so far though.
EDIT based on comments:
Here's what I would do for cycling through the list of start and end times:
[Data,Text] = xlsread('C:\Users\data.xlsx',2);
start_times = {'7:29:29 AM','7:29:35 AM','7:29:44 AM','7:29:49 AM'}; % etc...
end_times = {'2:30:29 PM','2:30:59 PM','2:31:22 PM','2:32:49 PM'}; % etc...
elapsed_time = zeros(length(start_times),1);
TestData = cell(length(start_times),1); % need a cell array because data can/will be of unequal lengths
for k=1:length(start_times)
IndexStart=strmatch(start_times{k},Text,'exact'); %start time
IndexEnd=strmatch(end_times{k},Text,'exact'); %end time
elapsed_time(k) = IndexEnd-IndexStart;
TestData{k} = Data([IndexStart: IndexEnd],:);
end
Use the "Import Data" from the Variable Tag in the Home menu. There you can set how you want the data to be imported like. With or without heading and the format.

Resources