calculated-columns

Syncing column width of between tables in two different frames, etc

白昼怎懂夜的黑 提交于 2020-01-10 04:03:19
问题 For reasons which are somewhat unavoidable (lots of legacy code, compatibility, design needs) I have the following problem: I have two tables, one directly below the other, but split between two frames (see the pseudo-example below my sig.). I need the column widths of these tables to synchronize exactly so that these two tables 'act' like one. The reason being to have a 'header' table which will not scroll above a 'data' table which can scroll. Now there are a few obvious suggestions which

Syncing column width of between tables in two different frames, etc

百般思念 提交于 2020-01-10 04:03:16
问题 For reasons which are somewhat unavoidable (lots of legacy code, compatibility, design needs) I have the following problem: I have two tables, one directly below the other, but split between two frames (see the pseudo-example below my sig.). I need the column widths of these tables to synchronize exactly so that these two tables 'act' like one. The reason being to have a 'header' table which will not scroll above a 'data' table which can scroll. Now there are a few obvious suggestions which

R for loop: create a new column with the count of a sub str from a different column

假装没事ソ 提交于 2020-01-05 10:25:11
问题 I used to fiddle with R and now it all seems to have escaped me . . . I have a table with a few hundred columns and about 100k rows. One of those columns contains strings that sometimes have commas in them (e.g. chicken,goat,cow or just chicken). I need a script with a (I believe) for loop that can create a new column (I know the new column code should not be in the for loop), count the number of commas (or the number of entries in the column in question less one) and add one so I can find

How to calculate multiple columns from multiple columns in pandas

萝らか妹 提交于 2020-01-02 11:05:12
问题 I am trying to calculate multiple colums from multiple columns in a pandas dataframe using a function. The function takes three arguments -a-, -b-, and -c- and and returns three calculated values -sum-, -prod- and -quot-. In my pandas data frame I have three coumns -a-, -b- and and -c- from which I want to calculate the columns -sum-, -prod- and -quot-. The mapping that I do works only when I have exactly three rows. I do not know what is going wrong, although I expect that it has to do

Creating a new column in Panda by using lambda function on two existing columns

99封情书 提交于 2020-01-01 01:26:51
问题 I am able to add a new column in Panda by defining user function and then using apply. However, I want to do this using lambda ; is there a way around? For Example, df has two columns a and b . I want to create a new column c which is equal to the longest length between a and b . Some thing like: df['c'] = df.apply(lambda x, len(df['a']) if len(df['a']) > len(df['b']) or len(df['b']) ) One approach: df = pd.DataFrame({'a':['dfg','f','fff','fgrf','fghj'], 'b' : ['sd','dfg','edr','df','fghjky']

Pandas DataFrame - assign 1,0 values based on other column

牧云@^-^@ 提交于 2019-12-31 02:34:06
问题 I've got a dataframe containing country names & their percentage of energy output. I need to add a new column that assigns a 1 or 0, based on whether the country's energy output is above or below the median of energy output. Some dummy code is: import pandas as pd def answer(): df = pd.DataFrame({'name':['china', 'america', 'canada'], 'output': [33.2, 15.0, 5.0]}) df['newcol'] = df.where(df['output'] > df['output'].median(), 1, 0) return df['newcol'] answer() the code returns ValueError:

SQL Server Reference a Calculated Column

◇◆丶佛笑我妖孽 提交于 2019-12-30 07:52:10
问题 I have a select statement with calculated columns and I would like to use the value of one calculated column in another. Is this possible? Here is a contrived example to show what I am trying to do. SELECT [calcval1] = CASE Statement, [calcval2] = [calcval1] * .25 回答1: No. All the results of a single row from a select are atomic. That is, you can view them all as if they occur in parallel and cannot depend on each other. If you're referring to computed columns, then you need to update the

Include an additional counter in the MySQL result set

a 夏天 提交于 2019-12-30 07:02:55
问题 Can I include an additional counter in a MySQL result set? I have the following query which gives me two columns back. I need an additional column (only in the result) indicating the row of each line in the result set. select orderid, round(sum(unitprice * quantity),2) as value from order_details group by orderid order by 2 desc limit 10 I need something like the following: 10865 1 17250.00 11030 2 16321.90 10981 3 15810.00 10372 4 12281.20 10424 5 11493.20 回答1: Try this: SET @counter = 0;

Include an additional counter in the MySQL result set

人盡茶涼 提交于 2019-12-30 07:02:04
问题 Can I include an additional counter in a MySQL result set? I have the following query which gives me two columns back. I need an additional column (only in the result) indicating the row of each line in the result set. select orderid, round(sum(unitprice * quantity),2) as value from order_details group by orderid order by 2 desc limit 10 I need something like the following: 10865 1 17250.00 11030 2 16321.90 10981 3 15810.00 10372 4 12281.20 10424 5 11493.20 回答1: Try this: SET @counter = 0;

Is there a way to pivot rows to columns in MySQL without using CASE?

时间秒杀一切 提交于 2019-12-28 16:16:40
问题 There are lots of posts out there on pivoting rows into columns for various databases. They seem to fall into two camps, using case statements or using a built in function of the database vendor. I am using MySQL and have not found anything so far on any built in function that will allow me to pivot on an arbitrary unknown number of row values that I want to pivot into columns. If I don't know the values ahead of time, I can't build the CASE queries that appear frequently on stackoverflow. I