How to read data on a specific row from excel by asking the name of that row? - excel-2007

I have the following excel file:
W1000x554 1032 408 52.1 29.5 70700 12300
W1000x539 1030 407 51.1 28.4 68700 12000
W1000x483 1020 404 46 25.4 61500 10700
W1000x443 1012 402 41.9 23.6 56400 9670
W1000x412 1008 402 40 21.1 52500 9100
W1000x371 1000 400 36.1 19 47300 8140
W1000x321 990 400 31 16.5 40900 6960
W1000x296 982 400 27.1 16.5 37800 6200
W1000x584 1056 314 64 36.1 74500 12500
I want to define a function that can ask the user for one of the first column's names and then read all the relevant data of that row later.
For example if the user defines W1000x412 then read : 1008 402 40 21.1 52500 9100.
Any ideas?

I suspect what #Marc means is that a formula such as in J2 below (copied across and down as necessary) will 'pick out' the values you want. It is not clear to me from your question whether these should be kept separate (as in Row2 of example) or strung together (CONCATENATE [&] as in J7 of example, where these are space [" "] delimited):
I am also not entirely sure about your 'define a function' but have assumed you do not require a UDF.
I have used Row1 to provide the offset for VLOOKUP, to save adjusting manually the formula for each column.
ColumnI is the expected user input, that might be best by selection from a Data Validation List with Source $A$2:$A$10.

Related

Dynamically Calculate difference columns based off slicer- POWERBI

I have a table with quarterly volume data, and a slicer that allows you to choose what quarter/year you want to see volume per code for. The slicer has 2019Q1 through 2021Q4 selections. I need to create dynamic difference column that will adjust depending on what quarter/year is selected in the slicer. I know I need to create a new measure using Calculate/filter but am a beginner in PowerBI and am unsure how to write that formula.
Example of raw table data:
Code
2019Q1
2019Q2
2019Q3
2019Q
2020Q1
2020Q2
2020Q3
2020Q4
11111
232
283
289
19
222
283
289
19
22222
117
481
231
31
232
286
2
19
11111
232
397
94
444
232
553
0
188
22222
117
411
15
14
232
283
25
189
Example if 2019Q1 and 2020Q1 are selected:
Code
2019Q1
2020Q1
Difference
11111
232
222
10
22222
117
481
-364
11111
232
397
-165
22222
117
411
-294
Power BI doesn't work that way. This is an Excel pivot table setup. You don't have any parameter to distinguish first and third or second and fourth row. They have the same code, so Power BI will aggregate their volumes. You could introduce a hidden index column but then why don't you simply stick to Excel? The Power BI approch to the problem would be to unpivot (stack) your table to a Code, Quarter and a Volume column, create 2 independent slicer tables for Minuend and Subtrahend and then CALCULATE your aggregated differences based on the SELECTEDVALUE of the 2 slicers.

Pandas extract hierarchical info?

I have a dataframe which describes serial numbers of items arranged in boxes:
df=pd.DataFrame({'barcode':['1000']*3+['2000']*4+['3000']*3, 'box_number': ['10']*2+['11']+['12']*4+['13','14','15'],'serials': map(str,range(800,810))})
barcode box_number serials
0 1000 10 800
1 1000 10 801
2 1000 11 802
3 2000 12 803
4 2000 12 804
5 2000 12 805
6 2000 12 806
7 3000 13 807
8 3000 14 808
9 3000 15 809
I want to group them hierarchically to output to hierarchical XML, so that every barcode has a list of box numbers which each have list of serials in them.
So I did a groupby which seems to do exactly what I want:
df.groupby(['barcode','box_number'])['serials'].apply(' '.join)
barcode box_number
1000 10 800 801
11 802
2000 12 803 804 805 806
3000 13 807
14 808
15 809
Name: serials, dtype: object
Now, I want to extract this info practically the way it is displayed so that I get a row for each barcode with data grouped similar to this:
row['1000']== {'10': '800 801','11':'802'}
row['2000']== {'12': '803 804 805 806'}
row['3000']== {'13': '807','14':'808','15':'809' }
But I can't seem to figure out how to get this done. I tried reset_index(), another groupby() -- but this doesn't work on existing result as it is a Series, but I can't seem to be able to understand the right way.
How should I this most concisely? I looked over questions here, but didn't seem to find similar issue.
Use dictionary comrehension for get nested dictonary with Series.xs and Series.to_dict:
s = df.groupby(['barcode','box_number'])['serials'].apply(' '.join)
d = {lev: s.xs(lev).to_dict() for lev in s.index.levels[0]}
print (d)
{'1000': {'10': '800 801', '11': '802'},
'2000': {'12': '803 804 805 806'},
'3000': {'13': '807', '14': '808', '15': '809'}}

Generate Seaborn Countplot using column value as count

For the following table
count_value
CPUCore Offline_RetentionAge
i7 183 4184
7 1981
30 471
i5 183 2327
7 831
30 250
Pentium 183 333
7 125
30 43
2 183 575
7 236
31 96
Is it possible to generate a seaborn countplot (or normal countplot) like the following (generated using sns.countplot(x='CPUCore', hue="Offline_BackupSchemaIncrementType", data=dfCombined_df))
Problem here is that I need to use the count_value as count, rather then really go and count the Offline_RetentionAge
I think you need seaborn.barplot:
sns.barplot(x="count_value", y="index", hue='Offline_RetentionAge', data=df.reset_index())

Set certain values in column B by matching it to another pair of columns

In First sheet I have many rows (but less than 10 thousand rows)
A B
198
198
198
197
197
225
…
…
…
119
229
In a Second sheet I have the matching values (some will be empty e.g 8.6 has no pair). Values in A are not sequential, while B is sequential from 0.1 to 21.1 (0.1 interval)
A B
139 0.1
211 0.2
208 0.3
208 0.3
207 0.4
…
…
…
229 4.0
…
…
…
119 7.4
…
…
…
- 8.6
198 8.5
197 8.7
…
…
…
225 9.9
After the macro/VBA I want the result in the First sheet, such as: (please can someone give me some hints, thank you very much)
A B
198 8.5
198 8.5
198 8.5
197 8.7
197 8.7
225 9.9
…
…
…
119 7.4
229 4.0
In the first sheet, use a VLOOKUP function to find corresponding matches in the second sheet (I'll call that Sheet2. with IFERROR to catch no matches. In the first sheet's B2 cell, use this formula,
=IFERROR(VLOOKUP($A2, 'Sheet2'!$A:$B, 2, FALSE), "")
VLOOKUP function
That will return the first value in column B that corresponds to a matching value in column A which seems to be what you want. Other options would be SUMIF, AVERAGEIF and/or COUNTIF.

How can I get the number of all bitcoins in the network?

I am trying to query the bitcoin daemon in order to find out what's the total amount of bitcoins mined/produced so far in order to calculate the market capitalization. However, I can't seem to find any command that does that.
I've checked the following link to no avail:
https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list
You can find that information from the number of blocks. 50 BTC per block were created for the first 210 000 blocks, then 25 BTC per block for the next 210 000 blocks, etc.
If I take, say:
http://bitcoincharts.com/
as I write this SO answer I can read:
Blocks 279383
Total BTC 12.235M
Starting from 279 383 blocks you can find:
210 000 * 50 = 10 500 000
(279 383 - 210 000) * 25 = 1 734 575
10 5000 + 1 734 575 = 12 234 575
12 234 575 which that site rounded up as "12.235M"
This is not 100% correct as the first 50 bitcoins were not usable etc. moreover it's a fact that quite a lot of the early bitcoins mined are lost forever.
But that approximation should be "close enough" and seems to be what most sites are using.