pivot

pandas: unstack rows into new columns

浪尽此生 提交于 2021-02-04 06:50:23
问题 i have a df that looks like this: a date c 0 ABC 2020-06-01 0.1 1 ABC 2020-05-01 0.2 2 DEF 2020-07-01 0.3 3 DEF 2020-01-01 0.4 4 DEF 2020-02-01 0.5 5 DEF 2020-07-01 0.6 i would like to "unstack" column 'a' so my new df looks like this a date1 c1 date2 c2 date3 c3 date4 c4 0 ABC 2020-06-01 0.1 2020-05-01 0.2 nan nan nan nan 1 DEF 2020-07-01 0.3 2020-01-01 0.4 2020-02-01 0.5 2020-07-01 0.6 how can i do this? 回答1: Use GroupBy.cumcount for helper counter for MultiIndex and reshape by DataFrame

ACCESS/SQL Combining multiple rows with one column into one row and creating multiple columns

半城伤御伤魂 提交于 2021-02-02 03:46:30
问题 I've looked at quite a few examples and nothing fits quite like I need it to. I have a table that has item numbers in one column and image links in another column. The issue I have is I need to combine rows that have the same item number but need to move the data in the HTML_LINK column to multiple columns called imagelink1, imagelink2, imagelink3. The max amount of imagelink columns I will need is 5. I tried a pivot table which worked to combine the rows, but it creates a column the name of

ACCESS/SQL Combining multiple rows with one column into one row and creating multiple columns

此生再无相见时 提交于 2021-02-02 03:44:04
问题 I've looked at quite a few examples and nothing fits quite like I need it to. I have a table that has item numbers in one column and image links in another column. The issue I have is I need to combine rows that have the same item number but need to move the data in the HTML_LINK column to multiple columns called imagelink1, imagelink2, imagelink3. The max amount of imagelink columns I will need is 5. I tried a pivot table which worked to combine the rows, but it creates a column the name of

一看就懂的快速排序

…衆ロ難τιáo~ 提交于 2021-01-30 08:16:22
概念 快速排序属于交换排序,主要步骤是使用基准元素进行比较,把小于基准元素的移动到一边,大于基准元素的移动到另一边。从而把数组分成两部分,然后再从这两部分中选取出基准元素,重复上面的步骤。过程如下: 紫色:基准元素 绿色:大于基准元素 黄色:小于基准元素 这种思路叫做分治法。 基准元素 基准元素的选取可随机选取。下面使用中我会使用第一位的元素作为基准元素。 排序过程 排序拆分过程如下图: 紫色为基准元素,(每一轮都重新选取) 绿色为其他元素 第一轮 第二轮 第三轮 如上图所示: 若元素个数为n,因为排序过程中需要和全部元素都比较一遍,所以时间复杂度为O(n), 而平均情况下排序轮次需要logn轮,因此快速排序的平均时间复杂度为O(nlogn)。 排序的实现方法 实现方法有双边循环法和单边循环法 双边循环法 首选选取基准元素(pivot)4,并设置指针left和right,指向数组最左和最右两个元素,如下: 第一次循环,先从right指针指向的数据(rightData)开始和基准元素比较 若 rightData >= pivot,则right指针向左移动,若 rightData < pivot,则right指针不移动,切换到left指针 left指针指向数据(leftData)与基准元素比较,若 leftData <= pivot,则left指针向右移动,若 leftData >

一看就懂的快速排序

夙愿已清 提交于 2021-01-30 07:29:41
概念 快速排序属于交换排序,主要步骤是使用基准元素进行比较,把小于基准元素的移动到一边,大于基准元素的移动到另一边。从而把数组分成两部分,然后再从这两部分中选取出基准元素,重复上面的步骤。过程如下: 紫色:基准元素 绿色:大于基准元素 黄色:小于基准元素 这种思路叫做分治法。 基准元素 基准元素的选取可随机选取。下面使用中我会使用第一位的元素作为基准元素。 排序过程 排序拆分过程如下图: 紫色为基准元素,(每一轮都重新选取) 绿色为其他元素 第一轮 第二轮 第三轮 如上图所示: 若元素个数为n,因为排序过程中需要和全部元素都比较一遍,所以时间复杂度为O(n), 而平均情况下排序轮次需要logn轮,因此快速排序的平均时间复杂度为O(nlogn)。 排序的实现方法 实现方法有双边循环法和单边循环法 双边循环法 首选选取基准元素(pivot)4,并设置指针left和right,指向数组最左和最右两个元素,如下: 第一次循环,先从right指针指向的数据(rightData)开始和基准元素比较 若 rightData >= pivot,则right指针向左移动,若 rightData < pivot,则right指针不移动,切换到left指针 left指针指向数据(leftData)与基准元素比较,若 leftData < pivot,则left指针向右移动,若 leftData >

Joining multiple rows into a single row without aggregation [Oracle]

房东的猫 提交于 2021-01-29 21:30:17
问题 I have the following query: select type, date, amount from table; And it gives the following result: TYPE DATE AMOUNT -------------------------------- A 30.6.2019 15 B 30.11.2019 20 C 22.12.2019 17 What I want to do is write a query that would return the following: TYPE1 DATE1 AMOUNT1 TYPE2 DATE2 AMOUNT2 TYPE3 DATE3 AMOUNT3 ------------------------------------------------------------------------------------------------------ A 30.6.2019 15 B 30.11.2019 20 C 22.12.2019 17 The number of rows

Joining multiple rows into a single row without aggregation [Oracle]

佐手、 提交于 2021-01-29 19:34:06
问题 I have the following query: select type, date, amount from table; And it gives the following result: TYPE DATE AMOUNT -------------------------------- A 30.6.2019 15 B 30.11.2019 20 C 22.12.2019 17 What I want to do is write a query that would return the following: TYPE1 DATE1 AMOUNT1 TYPE2 DATE2 AMOUNT2 TYPE3 DATE3 AMOUNT3 ------------------------------------------------------------------------------------------------------ A 30.6.2019 15 B 30.11.2019 20 C 22.12.2019 17 The number of rows

Hive: Is there a way to get the aggregates of all the numeric columns existing in a table?

走远了吗. 提交于 2021-01-29 14:37:44
问题 I have a table containing over 50 columns (both numeric and char), is there a way to get the overall statistics without specifying each column? As an example: a b c d 1 2 3 4 5 6 7 8 9 10 11 12 Ideally I would have something like: column_name min avg max sum a 1 5 9 15 b 2 6 10 18 c 3 7 11 21 d 4 8 12 24 Nevertheless, getting one aggregate at a time it would be more more than helpful. Any help/idea would be highly appreciated. Thank you, O 回答1: You can parse DESCRIBE TABLE output using AWK

Pivoting to append the last 6 payments for 24 loans

家住魔仙堡 提交于 2021-01-29 14:32:40
问题 I am building a query in Microsoft sql server where I want to find the active loans as well as some information on them. I have built out a common table expression that gives me the correct population. Now I need to get the last 6 payments starting from today. I have a another common table expression that gives all the payments and the payment data received but I am not sure how to pivot and append the last 6 payments such that I have something like this: This is what the query and output

Filtering table to create another table in Excel

非 Y 不嫁゛ 提交于 2021-01-29 10:17:13
问题 I need to receive values from a table where a condition is met. For example I have names and I need to take all values from a table where the name appears. For example the table consists of date, name, expenditures: Date Name Expenditures 2019-01-28 Sara 2.45 2019-04-26 John 32.67 2019-05-07 Peter 55.88 2019-06-14 Sara 62.09 2019-07-03 Sara 12.94 2019-09-30 Peter 5.64 I need to receive all expenditures which has been made by Sara and the Date days when it was done. The result should be the