Extract list data from a column

Extract list data from a column

I have a dataframe that looks really similar to this (basically a table of cities and their coordinates on a map. Note that coordinates is a list of X,Y values.

foo <- data.frame(
city = c("chicago", "new york"),
coordinate = I(list(list(10, 15), list(20, 25))),
myabbr = c("chi", "ny")
)

bar <- subset(foo, select=c("city", "coordinate"))

Right now, I can create a new table of only the city and the coordinates. I really want the X and Y values to be a separate column. This is what I tried

bar <- subset(foo, select=c("city", "coordinate[1]", "coordinate[2]"))

I’m not sure exactly how to do this though.

You can try something like cbind(as.character(bar$city), apply(bar, 1, function(i)unlist(i$coordinate)))
– Sotos
Jul 3 at 9:42

cbind(as.character(bar$city), apply(bar, 1, function(i)unlist(i$coordinate)))

I’ll give that a shot
– Cameron
Jul 3 at 9:42

Maybe cbind(foo, do.call(rbind, lapply(foo$coordinate, unlist))) ?
– zx8754
Jul 3 at 9:42

cbind(foo, do.call(rbind, lapply(foo$coordinate, unlist)))

That worked @zx8754. They both did technically, but that one had the proper datatypes
– Cameron
Jul 3 at 9:44

7 Answers
7

One more option for you, use listCol_w from splitstackshape.

listCol_w

splitstackshape

library(splitstackshape)
listCol_w(foo, "coordinate")
# city myabbr coordinate_fl_1 coordinate_fl_2
#1: chicago chi 10 15
#2: new york ny 20 25

Picking this because it’s arguably the most readable/simple
– Cameron
Jul 3 at 9:55

Because you depend on a highly specific package I can tell you that most R developers would just use the internal [[ function. Everyone will understand it whereas listCol_w needs a comment to be understood or looked up in the help.
– Juergen
Jul 3 at 10:06

[[

listCol_w

@Juergen What you write is probably true for most packages (e.g. I am struggling to understand ggplot2 internals though I’ve used the package for years). Still, this function is easy to read and remember, that’s why I posted it as another option.
– markus
Jul 3 at 10:20

ggplot2

You can access a list Element with list[[index]]. In your case you can extract it this way:

list[[index]]

foo <- data.frame(city=c("chicago", "new york"), coordinate=I(list(list(10, 15), list(20,25))), myabbr=c("chi", "ny"))
foo$coordinate_x = foo$coordinate[[1]]
foo$coordinate_y = foo$coordinate[[2]]
foo

What you need is to extract the X and Y elements from the list column “coordinate". List extraction is done like list[[index]] in R.

list[[index]]

i.e.

foo <- data.frame(city=c("chicago", "new york"), coordinate=I(list(list(10, 15), list(20,25))), myabbr=c("chi", "ny"))

bar <- subset(foo, select=c("city", "coordinate"))

bar$x <- bar$coordinate[[1]]
bar$y <- bar$coordinate[[2]]

bar$coordinate <- NULL

Thanks! This is actually what I ended up using!
– Cameron
Jul 3 at 9:58

The idea here is to unlist each row of your coordinates and cbind that with the cities, i.e.

unlist

cbind

cbind(city = as.character(bar$city),
setNames(data.frame(apply(bar, 1, function(i)unlist(i$coordinate))),
c('coordinate1', 'coordinate2')))

which gives,

city coordinate1 coordinate2
1 chicago 10 20
2 new york 15 25

We can unlist the column and bind back to original dataframe, try:

cbind(foo, do.call(rbind, lapply(foo$coordinate, unlist)))
# city coordinate myabbr 1 2
# 1 chicago 10, 15 chi 10 15
# 2 new york 20, 25 ny 20 25

bar%>%
group_by(city)%>%
mutate(coordinate=list(unlist(coordinate)),
n=list(paste0("coordinate",1:lengths(coordinate))))%>%
unnest%>%
spread(n,coordinate)

# A tibble: 2 x 3
# Groups: city [2]
city coordinate1 coordinate2
<fct> <dbl> <dbl>
1 chicago 10. 15.
2 new york 20. 25.

You can try a tidyverse as well

library(tidyverse)

foo %>%
mutate(coordinate=map(coordinate,~unlist(.) %>%
paste(., collapse=","))) %>%
separate(coordinate, into = c("x", "y"), sep=",")
# A tibble: 2 x 4
city x y myabbr
<fct> <chr> <chr> <fct>
1 chicago 10 15 chi
2 new york 20 25 ny

This gives you the expected result

.Last.value %>%
select(-myabbr)

By clicking “Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Python fetchall return true and false

Python fetchall return true and false

I have a python script that makes a fetchall():

connection = pymssql.connect(host='host', user='user', password='pw', database='database', as_dict=True)

cursor = connection.cursor()

cursor.execute("EXEC SPname")
data=cursor.fetchall()

My problem is that the cursor.fetchall() is returning True or Falses (and others columns with others values example above) but in the database the value is a bit 1 or 0 and when exported to CSV it puts the True or False and I want 1 or 0.

Sample data returned in SQL:

ID Price Price2 Price3 Active Opened Sent Enable
1 12234.09 1111.09 3444.36 1 1 1 0

2 Answers
2

You can use int()

int()

Ex:

print(int(True))
print(int(False))

Output:

1
0

Thank you for your answer and help. The problem is that the SP returns multiple columns, in this case 88, and I dont want to explicitly designates them because it has a lot of columns and I want something dynamic because if I alter the SP to return one more column I don’t want to alter the script to add the column. The objective is next do the this: a= csv.writer(fp, delimiter=';') for line in data: a.writerows(line)
– peixinho3
Jul 3 at 9:53

a= csv.writer(fp, delimiter=';') for line in data: a.writerows(line)

You do not need to alter the SP, instead modify the bool value right before writing to the csv file.
– Rakesh
Jul 3 at 9:55

Correct but that implies that i make: a= csv.writer(fp, delimiter=';') for line in data: line["mycolumn1"] = int(line["mycolumn1"]) line["mycolumn2"] = int(line["mycolumn2"]) line["mycolumn3"] = int(line["mycolumn3"]) a.writerows(line) And this take a lots of time and if I had a new bit value in the SP I have to add another condition in the script
– peixinho3
Jul 3 at 10:14

a= csv.writer(fp, delimiter=';') for line in data: line["mycolumn1"] = int(line["mycolumn1"]) line["mycolumn2"] = int(line["mycolumn2"]) line["mycolumn3"] = int(line["mycolumn3"]) a.writerows(line)

Can you post a sample of data?
– Rakesh
Jul 3 at 10:22

data

Question edited with sample.
– peixinho3
Jul 3 at 10:35

fetchall returns a list of tuples or dictionaries. The easiest way to convert them to integers is by mapping the int method to that list:

fetchall

int

data_in_integer_form = map(int, data)

Thank you for your help but the data returned is not only booleans it’s also decimal, strings, etc..
– peixinho3
Jul 3 at 10:21

Well, that’s a different question than the one stated in the first place. You said the query was returning True and False, not decimals and strings.
– Poshi
Jul 3 at 10:27

By clicking “Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Could anyone explain how the link is combined with the image in this site?

Could anyone explain how the link is combined with the image in this site?

Normally, when we want to add some url link to a image, we simply put that image inside a element.

However, I just found that in this page:
https://uk.burberry.com/mens-trench-coats/

The link of each coat is separated from the image. However, when the mouse is put on the coat image, we can still detect the link.

Could anyone explain how does this work?

1 Answer
1

The link on the page you mentioned is position: absolute; and “moved" over the actuall image which is indeed placed in an other element.

position: absolute;

https://developer.mozilla.org/en-US/docs/Web/CSS/position

By clicking “Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Laravel 5.6 – Using @foreach in a markdown

Laravel 5.6 – Using @foreach in a markdown

Hello stackoverflowers,

I try to render a @foreach loop in a markdown template. But I don’t get it to work. I found this Laravel- use @foreach in markdown mail, but it didn’t take me futher.

I studied the laraval docs but it seems that I’m unable to find my issue.

I try to generate a mail with all information from the supplier-table. Therefore I use the Supplier Class.

Maybe someone could open my eyes or could give me a hint in the right direction.

Route:

Route::get('/mail',function(){

$suppliers = AppModelSupplierSupplier::all();
return new AppMailSupplierCertificates($suppliers);
});

Mail-Class:

namespace AppMailSupplier;

use IlluminateBusQueueable;
use IlluminateMailMailable;
use IlluminateQueueSerializesModels;
use IlluminateContractsQueueShouldQueue;

use AppModelSupplierSupplier;

class Certificates extends Mailable
{
use Queueable, SerializesModels;

public $supplier;

public function __construct(Supplier $supplier)
{
//
$this->supplier = $supplier;

}

public function build()
{

return $this->markdown('email.supplier.test');
}
}

Markdown-File:

# Certificate:
@component('mail::table')
|No. | Company | Address
|:--------|:--------|----------:

@foreach($supplier as $detail)
| {{$detail->no}} | {{$detail->company}} | {{$detail->address}}
@endforeach
@endcomponent

I’m receiving this error:

Argument 1 passed to AppMailSupplierCertificates::__construct()
must be an instance of AppModelSupplierSupplier, instance of
IlluminateDatabaseEloquentCollection given, called in C:xampphtdocs
ppsroutesmail.php on line 7

Am I completely wrong?

Thank you in advance.

@foreach is only for blade template. Its not about laravel.
– user254153
Jul 3 at 9:46

2 Answers
2

Alright! This seems to be the solution in the Mail-Class:

public function build()
{

$suppliers = Supplier::all();

return $this->markdown('email.supplier.certificates')->with(['suppliers'=>$suppliers]);
}

But I’m still open for better solutions!

exactly .. as you are calling a view you should pass all the data that’s used
– Athul Raj
Jul 3 at 14:27

You are expecting a single Supplier in your constructor, but you are giving it the collection of suppliers when you initialize it.

public function __construct(Supplier $supplier)
{
$this->supplier = $supplier;
}

However, it should be something like this:

use IlluminateDatabaseEloquentCollection;

class Certificates extends Mailable
{
public $suppliers;

public function __construct(Collection $suppliers)
{
$this->suppliers = $suppliers;
}

public function build()
{
return $this->markdown('email.supplier.test');
}
}

Thank you very much!
– T.Gerste
Jul 6 at 9:48

@T.Gerste Np, can you mark my answer as the correct one please?
– Chin Leung
Jul 6 at 17:57

By clicking “Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

How to prompt/hide a password when opening a CMD?

How to prompt/hide a password when opening a CMD?

I have some code inside a batch file that when I run it my passwords do get hidden. However I am trying to build it so that I can place the code inside any batch file and you will then need to enter the correct password. Currently you can type anything and be allowed access. I know my code isn’t written so you have to type something specific in, that is why I am asking here.

@echo off
set "psCommand=powershell -Command "$pword = read-host 'Enter Password' -
AsSecureString ; ^
$BSTR=[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pword); ^
[System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)""
for /f "usebackq delims=" %%p in (`%psCommand%`) do set password=%%p
echo %password%

I wish to keep my code as it is because it currently hides what gets typed, but I need someone to add some sort of password checker.

Possible duplicate of Batch File Command Hide Password
– tukan
Jul 3 at 10:30

@tukan No i already have mine hidden i want to make it so you have to enter the correct password using the code i have already written
– connorg98
Jul 3 at 10:46

You do the password checking against what entity? Where is the correct password?
– tukan
Jul 3 at 10:58

if "%password%" neq "MySecretString" goto :eof
– Stephan
Jul 3 at 15:13

if "%password%" neq "MySecretString" goto :eof

Hey @tukan your solve worked thank you very much for showing me to the correct page!
– connorg98
Jul 4 at 8:53

1 Answer
1

Adding the answer based on comments, so this question is answered:

If you use Batch File command hide password have it before your Game code you will have the requested password in your variable.

You can also do a CALL get_password.bat (if you store the batch code and get the return value from that CALL).

CALL get_password.bat

CALL

Thank you Connorg98.

By clicking “Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

How do I flat a Nested Json file in Python?

How do I flat a Nested Json file in Python?

I have a nested Json file with arrays.
I want to flat it so there won’t be nested Jsons.

For example:

enter image description here

Code for Json:
https://jsonblob.com/4b255e51-7e9f-11e8-b89c-37203846213e

This Json has sub-Json and also array that contains Json.

The source is:

enter image description here

Output should be:

enter image description here

If there are arrays that contains a single Json they can be ignored. But if they have also sub-json they should be treated as above. Basically from my point of view each array is like a separated Json file.

I know that flating the Json can be done as:

from pandas.io.json import json_normalize
json_normalize(sample_object)

But this won’t work with arrays.

Any idea how to make this work?

EDIT:

This is how arrays should be handled:
source:

enter image description here

Output:

enter image description here

Which means first Json in array stays as is {0}, {1} etc… but the sub-jsons are flatted. There are no columns of attributes_0_value ! Basically convert it to array with a single Json. No nesting (unless there is another array).

attributes_0_value

2 Answers
2

Try using this:

import pandas as pd
import json

response = {u'total': 1245, u'limit': 2, u'results': [{u'customer': {u'lastName': u'rtyrtyrt', u'userAccountId': None, u'id': 637, u'firstName': u'rtyrtyrty', u'email': u'ddfgdfg@dfsdfgdfg.ggg'}, u'shippingAddress': {u'city': u'rtyrtyrtyrty', u'vatNumber': None, u'firstName': u'rtyrtyrty', u'companyName': None, u'country': {u'defaultCulture': {u'languageName': u'English', u'code': u'en-GB', u'id': 2, u'name': u'English'}, u'onlineStoreActive': True, u'currency': {u'symbol': u'xa3', u'code': u'GBP', u'id': 2, u'currencyCulture': u'en-GB', u'numericCode': 826}, u'locale': None, u'isO2LetterCode': u'GB', u'vatPercentage': 20.0, u'continent': u'Europe ', u'isoNumericCode': u'826', u'invariantName': u'UNITED KINGDOM', u'id': 2, u'isO3LetterCode': u'GBR'}, u'stateProvince': None, u'lastName': u'rtyrtyrt', u'zipCode': u'5464556', u'email': u'ddfgdfg@dfsdfgdfg.ggg', u'addressLine2': None, u'addressLine1': u'tyrtyrty', u'phoneNumber': u'45644443456456546', u'addressName': None, u'id': 861}, u'orderDateUtc': u'0001-01-01 00:00', u'shoppingCardId': 0, u'paymentType': {u'code': u'SafeCharge', u'invariantName': u'Credit Card', u'id': 50}, u'orderNumber': u'0100000845', u'giftMessage': u'', u'storeId': 1, u'shippingService': {u'deletedOn': None, u'code': u'ROYALSTD', u'courier': None, u'updatedOn': u'2018-01-24 09:23', u'locale': None, u'createdOn': u'2018-01-24 09:23', u'storeId': 1, u'sortOrder': 1, u'invariantName': u'Royal Mail Standard', u'id': 1}, u'referenceOrderNumber': u'', u'totals': {u'shippingChargesNet': 3.95, u'orderLevelDiscount': 0.0, u'grandTotal': 8.95, u'vatPercentage': 20.0, u'shippingChargesDiscount': 0.0, u'shippingCharges': 3.95, u'units': 1, u'salesTaxPerc': 0.0, u'subTotal': 5.0, u'salesTax': 1.4916666666666667}, u'currency': {u'symbol': u'xa3', u'code': u'GBP', u'id': 2, u'currencyCulture': u'en-GB', u'numericCode': 826}, u'status': {u'invariantName': u'Waiting PackingList', u'id': 4, u'name': None}, u'billingAddress': {u'city': u'rtyrtyrtyrty', u'vatNumber': None, u'firstName': u'rtyrtyrty', u'companyName': None, u'country': {u'defaultCulture': {u'languageName': u'English', u'code': u'en-GB', u'id': 2, u'name': u'English'}, u'onlineStoreActive': True, u'currency': {u'symbol': u'xa3', u'code': u'GBP', u'id': 2, u'currencyCulture': u'en-GB', u'numericCode': 826}, u'locale': None, u'isO2LetterCode': u'GB', u'vatPercentage': 20.0, u'continent': u'Europe ', u'isoNumericCode': u'826', u'invariantName': u'UNITED KINGDOM', u'id': 2, u'isO3LetterCode': u'GBR'}, u'stateProvince': None, u'lastName': u'rtyrtyrt', u'zipCode': u'5464556', u'email': u'ddfgdfg@dfsdfgdfg.ggg', u'addressLine2': None, u'addressLine1': u'tyrtyrty', u'phoneNumber': u'456456456546', u'addressName': None, u'id': 861}, u'items': [{u'orderId': 844, u'discountEach': 0.0, u'cancellationId': 0, u'orderedQty': 1, u'giftMessage': u'', u'orderLevelDiscountEach': 0.0, u'historicalCategories': , u'giftFrom': u'', u'netShippingChargesEach': 3.95, u'promotionItemIds': , u'variantId': 11282, u'attributes': [{u'value': u'', u'key': u'ProductSeason'}], u'priceEach': 5.0, u'isGift': False, u'id': 939, u'giftTo': u''}], u'attributes': [{u'value': u'2', u'key': u'CustomerCultureId'}, {u'value': u'185.13.248.67', u'key': u'IpAddress'}, {u'value': u'UA', u'key': u'IpCountryCode'}, {u'value': u'OLS', u'key': u'OrderSource'}, {u'value': u'111790', u'key': u'SafeCharge_AuthCode'}, {u'value': u'UQBzAGQAaAB3ADgAMgB0AE4AagBHADUAegBpAHMAIwA7AC4ANgA3AFEAXwBMAGAAKwAqAHIAVgBGAEcAKQBFAD0ASQA8AC4ATgA0AD8ANQA+AFAAMwA=', u'key': u'SafeCharge_Token'}, {u'value': u'1512424599', u'key': u'SafeCharge_TransactionId'}, {u'value': u'1', u'key': u'StoreId'}], u'isGift': False, u'id': 844}, {u'customer': {u'lastName': u'dfgdfg', u'userAccountId': None, u'id': 638, u'firstName': u'dfgdfg', u'email': u'hfghfgh@dfdfg.fdg'}, u'shippingAddress': {u'city': u'fghfghhf', u'vatNumber': None, u'firstName': u'dfgdfg', u'companyName': None, u'country': {u'defaultCulture': {u'languageName': u'English', u'code': u'en-GB', u'id': 2, u'name': u'English'}, u'onlineStoreActive': True, u'currency': {u'symbol': u'xa3', u'code': u'GBP', u'id': 2, u'currencyCulture': u'en-GB', u'numericCode': 826}, u'locale': None, u'isO2LetterCode': u'GB', u'vatPercentage': 20.0, u'continent': u'Europe ', u'isoNumericCode': u'826', u'invariantName': u'UNITED KINGDOM', u'id': 2, u'isO3LetterCode': u'GBR'}, u'stateProvince': None, u'lastName': u'dfgdfg', u'zipCode': u'4564566', u'email': u'hfghfgh@dfdfg.fdg', u'addressLine2': None, u'addressLine1': u'fghfghfgh', u'phoneNumber': u'567567567', u'addressName': None, u'id': 862}, u'orderDateUtc': u'0001-01-01 00:00', u'shoppingCardId': 0, u'paymentType': {u'code': u'SafeCharge', u'invariantName': u'Credit Card', u'id': 50}, u'orderNumber': u'0100000846', u'giftMessage': u'', u'storeId': 1, u'shippingService': {u'deletedOn': None, u'code': u'ROYALSTD', u'courier': None, u'updatedOn': u'2018-01-24 09:23', u'locale': None, u'createdOn': u'2018-01-24 09:23', u'storeId': 1, u'sortOrder': 1, u'invariantName': u'Royal Mail Standard', u'id': 1}, u'referenceOrderNumber': u'', u'totals': {u'shippingChargesNet': 3.95, u'orderLevelDiscount': 0.0, u'grandTotal': 8.95, u'vatPercentage': 20.0, u'shippingChargesDiscount': 0.0, u'shippingCharges': 3.95, u'units': 1, u'salesTaxPerc': 0.0, u'subTotal': 5.0, u'salesTax': 1.4916666666666667}, u'currency': {u'symbol': u'xa3', u'code': u'GBP', u'id': 2, u'currencyCulture': u'en-GB', u'numericCode': 826}, u'status': {u'invariantName': u'Shipped', u'id': 6, u'name': None}, u'billingAddress': {u'city': u'fghfghhf', u'vatNumber': None, u'firstName': u'dfgdfg', u'companyName': None, u'country': {u'defaultCulture': {u'languageName': u'English', u'code': u'en-GB', u'id': 2, u'name': u'English'}, u'onlineStoreActive': True, u'currency': {u'symbol': u'xa3', u'code': u'GBP', u'id': 2, u'currencyCulture': u'en-GB', u'numericCode': 826}, u'locale': None, u'isO2LetterCode': u'GB', u'vatPercentage': 20.0, u'continent': u'Europe ', u'isoNumericCode': u'826', u'invariantName': u'UNITED KINGDOM', u'id': 2, u'isO3LetterCode': u'GBR'}, u'stateProvince': None, u'lastName': u'dfgdfg', u'zipCode': u'4563334566', u'email': u'hfghfgh@dfdfg.fdg', u'addressLine2': None, u'addressLine1': u'fghfghfgh', u'phoneNumber': u'567567567', u'addressName': None, u'id': 862}, u'items': [{u'orderId': 845, u'discountEach': 0.0, u'cancellationId': 0, u'orderedQty': 1, u'giftMessage': u'', u'orderLevelDiscountEach': 0.0, u'historicalCategories': , u'giftFrom': u'', u'netShippingChargesEach': 3.95, u'promotionItemIds': , u'variantId': 11282, u'attributes': [{u'value': u'', u'key': u'ProductSeason'}], u'priceEach': 5.0, u'isGift': False, u'id': 940, u'giftTo': u''}], u'attributes': [{u'value': u'2', u'key': u'CustomerCultureId'}, {u'value': u'115.11.118.67', u'key': u'IpAddress'}, {u'value': u'UA', u'key': u'IpCountryCode'}, {u'value': u'OLS', u'key': u'OrderSource'}, {u'value': u'111335', u'key': u'SafeCharge_AuthCode'}, {u'value': u'UQA1AEYASgBVAEgAcgBvAE8AWAAlAFMAaABcAGAAMwA0AG4ATABiAHAAcQBoAEkAawB6AHMANQBXAEgAUQApACQATwBpAEQAUABAAGcAKwBcADQAMwA=', u'key': u'SafeCharge_Token'}, {u'value': u'1512424624', u'key': u'SafeCharge_TransactionId'}], u'isGift': False, u'id': 845}], u'offset': 0}

sample_object = pd.DataFrame(response)['results'].to_dict()

def flatten_json(y):
out = {}

def flatten(x, name=''):
if type(x) is dict:
for a in x:
flatten(x[a], name + a + '_')
elif type(x) is list:
out[name[:-1]] = x
else:
out[name[:-1]] = x

flatten(y)
return out

flat = {k: flatten_json(v) for k, v in sample_object.items()}

with open('flat.json', 'w') as jsonfile:
jsonfile.write(json.dumps(flat))

Comments are not for extended discussion; this conversation has been moved to chat.
– Yvette Colomb
Jul 4 at 11:54

I personally use this procedure.

First store the JSON data as string (or, load from url or file)

enter image description here

use nested_to_record() method from pandas

import json
from pandas.io.json.normalize import nested_to_record

json_dic = json.loads(json_str)
flat = nested_to_record(json_dic, sep='_')

for key in flat:
print key, flat[key]

Output:

enter image description here

Sorry but this doesn’t answer my question. You embedded the row number in the column names… you removed all Jsons – this is not what I was referring to… See my examples in the post.
– jack
Jul 3 at 13:01

By clicking “Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Calculated Column based on the number in Text area

Calculated Column based on the number in Text area

I hope you can help. What I am trying to achieve is a column that recalculates a column based on the value entered in the Text Area. Let me explain.

Text Area

In Pic 1 you can see the page called Rename Dashboard, and I also have a page called Percentage Schema see Pic 2

On Page Percentage Schema you will see that Column 1 is the Product Code, Column 2 is the Product name (I have covered with text doc to protect info), Column 3 is the price of the product and Columns 4 out to 12 tell me what 'Schema' this product is on and what discount can be earned by being on this Schema.

Percentage Schema

Product Code

Product name

product

'Schema'

So if you observe in Pic 2 Product Code 708230 has a 1 in the first row of Column 4 meaning that this product will receive a 20% discount for being on number 1 Schema, If you look at Column 5 you will see the number 2 and if you navigate directly down and across this product will get a 16% discount, the product receives different discount on different Schema

So in Pic 1 what I would like to happen is that if I type C000004 into Customer Number Area in Text area the pivots will filter, for C000004 (no big deal easily done) but then if I type 5 into Schema number area then, I want the RUBU column in the Pivot to recalculate the percentage discount for each product code in the Pivot based on the number I type in the Schema Number area.

So at present C000004 is locked into Schema 7 via a join and the RUBU column does not calculate any discount for it being on 7.

What I need is for the Schema Column to accept what number I put in the Schema Number area in the text area, then apply the product specific discount based on the data stored on the Percentage Schema page, to the products in the second column of the pivot on Rename Dashboard and then recalculate the RUBU column

Essentially what I need is for the Schema Column to be dynamic so that It will accept whatever number I put in the Schema Number text area and then based on that number, I need the RUBU Column to recalculate totals for a customer. So if C000004 was to change from Schema 7 to Schema 5 I should see a change in the RUBU column in the pivot.

Its an INDEX MATCH function against the numbers stored in the top row of Percentage Schema page.

INDEX MATCH

I’m not sure if it is a dynamic function in the text area that I need or a calculated column for RUBU or a dynamic custom column for Schema…

Sorry for the long post it was tough to explain and as always ANY AND ALL HELP IS GREATLY APPRECIATED

Pic 1
enter image description here

Pic 2
enter image description here

By clicking “Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Creating star schema from csv files using Python

Creating star schema from csv files using Python

I have 6 dimension tables, all in the form of csv files. I have to form a star schema using Python. I’m not sure how to create the fact table using Python. The fact table (theoretically) has at least one column that is common with a dimension table.

How can I create the fact table, keeping in mind that quantities from multiple dimension tables should correspond correctly in the fact table?

I am not allowed to reveal the code or exact data, but I’ll add a small example. File 1 contains the following columns: student_id, student_name. File 2 contains : student_id, department_id, department_name, sem_id. Lastly File 3 contains student_id, subject_code, subject_score. The 3 dimension tables are in the form of csv files. I now need the fact table to contain: student_id, student_name, department_id, subject_code. How can I form the fact table in that form? Thank you for your help.

2 Answers
2

Reading certain blogs look like it is not a good way to handle such cases in python in memory but still if the below post make sense you cn use it

Fact Loading

The first step in DW loading is dimensional conformance. With a little cleverness the above processing can all be done in parallel, hogging a lot of CPU time. To do this in parallel, each conformance algorithm forms part of a large OS-level pipeline. The source file must be reformatted to leave empty columns for each dimension’s FK reference. Each conformance process reads in the source file and writes out the same format file with one dimension FK filled in. If all of these conformance algorithms form a simple OS pipe, they all run in parallel. It looks something like this.

src2cvs source | conform1 | conform2 | conform3 | load
At the end, you use the RDBMS’s bulk loader (or write your own in Python, it’s easy) to pick the actual fact values and the dimension FK’s out of the source records that are fully populated with all dimension FK’s and load these into the fact table.

Would you like to add any code you’re currently stuck on? Please add a Minimal, Complete, and Verifiable example including the file content and expected output

I am not allowed to reveal the code or exact data, but I’ll add a small example. File 1 contains the following columns: student_id, student_name. File 2 contains : student_id, department_id, department_name, sem_id. Lastly File 3 contains student_id, subject_code, subject_score. The 3 dimension tables are in the form of csv files. I now need the fact table to contain: student_id, student_name, department_id, subject_code. How can I form the fact table in that form? Thank you for your help.
– pack24
Jul 3 at 9:58

@AkshayVenkatesh Please edit your question to include that information. A comment to an answer which is not an answer is not the appropriate place for this.
– Adrian W
Jul 3 at 11:11

@AdrianW I have edited my question. However downvoting because I have not made an attempt/no code is irrational, since I have mentioned that I am strictly now allowed to disclose any code or data. I have made an attempt, but I am not allowed to disclose any information.
– pack24
Jul 3 at 11:42

@pack24 Please read how to ask. Don’t assume everybody can guess what your problem is without background information. That’s why a MCVE is usually required. If you can’t provide that information because it is confidential, then it is probably not a good idea to ask a public place for help. If you can provide something similar enough to describe your problem without violating your confidentiality constraints, that’s OK. Therefore I revoked my downvote now.
– Adrian W
Jul 3 at 15:40

By clicking “Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Vaadin 10/Flow theming with Lumo

Vaadin 10/Flow theming with Lumo

I’m having some trouble understanding Vaadin 10 theming: I’ve read all documentation on site but I can’t solve my problem.

For example: if I start a plain Vaadin 8 application from scratch, when I stop the server I get a nice notification from disconnection:

enter image description here

But with a new Vaadin 10 starter (project base), i get this ugly notification
enter image description here

Both application are standard without any edit from Vaadin starters.
I’ve tried playing with shared-styles.html but without success.

My questions, all vaadin 10 related:

Thanks

1 Answer
1

@Theme(value = Lumo.class, variant = Lumo.DARK)

html{--lumo-base-color: aliceblue;}

And here’s how you can customize the disconnection notification:

<custom-style>
<style>
html {
--lumo-base-color: aliceblue;
}

.v-reconnect-dialog {
visibility: visible;
border: 1px solid lightslategray;
background-color: slategray;
color: lightgray;
box-shadow: 0.2em 0.2em 0.2em rgba(0, 0, 0, .4);
border-radius: 4px;
}

.custom {
color: lightskyblue;
}
</style>
</custom-style>

It worked perfectly, thanks so much! In this case I don’t have to import anything into shared-style.html because I’m using Lumo, and it’s all packed into Vaadin, right?
– Leviand
Jul 3 at 13:19

Right. No need to import anything from the shared-style.tml file.
– Alejandro Duarte
Jul 3 at 13:27

shared-style.tml

By clicking “Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Create table view like Appstore App Today View section Animation on click of Any View

Create table view like Appstore App Today View section Animation on click of Any View

I want to create tableview like Appstore Today view section Animation on click of card View (Apps in card view)

Its UICollectionView i think!
– SPatel
Jul 3 at 9:39

Please check these links. github.com/filletofish/CardsLayout github.com/intuit/CardParts
– aBilal17
Jul 3 at 9:42

can’t we make it in tableview ?
– navjot
Jul 3 at 9:42

I want to create the animation expand and collapse of the view same like when we click on App Store items in today view section.
– navjot
Jul 3 at 9:43

Yes you can use tableView as well for it.
– aBilal17
Jul 3 at 9:45

By clicking “Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.