join

Join two tables on ID where table one has duplicates and table two does not

Join two tables on ID where table one has duplicates and table two does not Question: I have two tables, Table A[‘id’, ‘col1’] and Table B[‘id’, ‘col3’]. Table A has duplicate values in ‘id’ column and its important that those duplicate row stay as they are but Table B has single pair for ‘id’ and …

Total answers: 2

How to resolve TypeError: sequence item 1: expected str instance, int found (Python)?

How to resolve TypeError: sequence item 1: expected str instance, int found (Python)? Question: Seeking for your assistance regarding this issue and I’m trying to resolve it, tried so many syntax but still getting the same error. I got multiple csv files to be converted and I’m pulling the same data, the script works for …

Total answers: 1

How to perform split/merge/melt with Python and polars?

How to perform split/merge/melt with Python and polars? Question: I have a data transformation problem where the original data consists of "blocks" of three rows of data, where the first row denotes a ‘parent’ and the two others are related children. A minimum working example looks like this: import polars as pl df_original = pl.DataFrame( …

Total answers: 1

Uppercase every other word in a string using split/join

Uppercase every other word in a string using split/join Question: I have a string: string = "Hello World" That needs changing to: "hello WORLD" Using only split and join in Python. Any help? string = "Hello World" split_str = string.split() Can’t then work out how to get first word to lowercase second word to uppercase …

Total answers: 4

python – Joining two columns pandas – returning NA if any value is NA, however need to return real join

python – Joining two columns pandas – returning NA if any value is NA, however need to return real join Question: I have dataframe: df = pd.DataFrame({‘student_id’: [71, 63, 23], ‘student_name’: [nan, ‘Peter Andrews’, ‘Amy Powers’], }) I am creating new column column which joins id + name using df[‘student_id_name’] = df[‘student_id’].astype(str) + ‘ ‘ …

Total answers: 2

Does DolphinDB have an equivalent method to Python join?

Does DolphinDB have an equivalent method to Python join? Question: In Python, I can join all elements into a string separated by a string separator with method join(). >>> ‘,’.join(["{}D".format(i) for i in range(1,6)]) ‘1D,2D,3D,4D,5D’ How can I implement the function equivalent to join in DolphinDB? Asked By: ajldfa || Source Answers: You may try …

Total answers: 1

Why does my list have extra double brackets?

Why does my list have extra double brackets? Question: arr_list = [] arr = [‘5’, ‘6’, ‘2’, ‘4’, ‘+’] arr_list.append([”.join(arr[0:4])]) print(arr_list) Ouput: [[‘5624′]] Why does the output have 2 sets of square brackets? I only want one. Thanks in advnace. Asked By: Benjamin McDowell || Source Answers: Use: arr_list.append(”.join(arr[0:4])) Answered By: brenodacosta You’re appending a …

Total answers: 5

How to join second elements in tuples using group by first element python

How to join second elements in tuples using group by first element python Question: I have a list of tuples a = [(‘name’, ‘color’),(‘fruit’, ‘color’),(‘thing’, ‘type’),(‘sport’, ‘type’)] I want to join first elements grouped by second element. The output should look like. a = [(‘name fruit’, ‘color’),(‘thing sport’, ‘type’)] Asked By: Anonymous || Source Answers: …

Total answers: 3

Appending a large amount of columns into 1 column

Appending a large amount of columns into 1 column Question: I have a dataset of ~700 columns. I’d like to join all columns into a single column. Input: id | A | B | C | D | E | F | … | Z 0 | yes | no | yes | no | …

Total answers: 5