Pandas move values from row to first three columns - pandas

I have a dataframe with two columns. in first column I have a product and second column the name of the client. I have for every product >1 and <4 clients. I need to create a dataframe with first column the product and column B , C, D the client related to the product
Any suggestion

Related

How to reorganise a table basis a criteria

I have a table where columns exist at different rows as shown in Problem figure.
I am able to identify the rows of column headers (Numbered 1 in column A) and there values(Numbered 2,3 onwards in Column A).
I want collate it in a neat table as shown in Solution table; where all Column headers are in one row and subsequently we have their values.
Problem and expected results are as shown in picture

How do I assign group Id's from one table to rows in another based on datetimes being between start and finish datetimes?

I have two tables. Table A has two columns, one datetime, one numeric. Table B has several columns, but three essential columns to this problem: a unique Id for each row, a start datetime and an end datetime. Table A has multiple rows for each single row of Table B, so I want to assign the row Id's from Table B to the corresponding rows of Table A based on whether the Table A datetime occurs BETWEEN the start datetime and end datetime of Table B. Assume no rows in Table B have overlapping start-end intervals.
Imagine essentially many experiments were done with start and end times, but the measurements for the experiment were recorded separately without the experiment id's and only with datetimes to reference during which experiment the observations were made.
HOW DO I GET THE TABLE B ID'S ASSIGNED TO THE OBSERVATIONS IN TABLE A?
Please and most definitely thank you.
I would try someting like that:
select a.*, b.id
from a, b
where a.dt between b.start_dt and b.end_dt;

Delete duplicate value when the duplicate values are not in the same column for multiple ids in sql

my data is consists of many customer id with column a and column b. Can somebody suggest me how to remove duplicated in such time where the combinations of the two columns are interchanged form of the columns
Below is the snippet of my data
Customer_Id Col_1 Col_2
1215682 A B
1215682 B A
The combination above formed are AB & BA , how can we remove such duplicates
Similar to this customer id there are many other customer id.

How would you total the values in one column and keep a distinct value in another?

I have a database table that has multiple codes in one column that correspond to certain values in another column. For example, a particular code in column A corresponds to a value in column B. There are thousands of duplicate entries in column A that correspond to different values in column B. I want to add up all of the values in column B that have the particular code in column A, while only keeping one copy of the code from column A. You may think of the columns as key-value pairs, where column A contains the key and column B contains the value.
Basically, I want to add all the values in column B where column A is a specific value, and I want to do for this all of the unique "keys" in column A. I'm sure that this is a simple task; however, I am pretty new to SQL. Any help would be greatly appreciated.
Here is the result I'm looking for.
This should work:
SELECT
A,
SUM(B) AS sum_b
FROM [yourTable]
GROUP BY A
SELECT COLUMNA, SUM(ISNULL(COLUMNB,0)) AS TOTAL
FROM
dbo.TableName
GROUP BY COLUMNA

Numbers help creating aggregates

I have a table with rows of multiple types. How do I create another table from it so that the rows in this table reflect the sum of all rows of each type from the previous table.
For e.g. I have a Table1 with 5 rows of type A, 6 rows of Type B. I want to create a table (Table2) that contains one row of type A (which is sum of all the 5 rows from Table1) and one row of type B (again this is the sum of all 6 rows from Table1).