join

Join rows and concatenate attribute values in a csv file with pandas

Join rows and concatenate attribute values in a csv file with pandas Question: I have a csv file structured like this: As you can see, many lines are repeated (they represent the same entity) with the attribute ‘category’ being the only difference between each other. I would like to join those rows and include all …

Total answers: 2

Combine multiple columns as a string in python

Combine multiple columns as a string in python Question: I am trying to combine multiple columns from a dataframe into a new column in the same dataframe. Those columns could either have a string value or are Na or NaN. Whenever one column is Na/NaN, I would like these columns to not be included in …

Total answers: 2

string .join method confusion

string .join method confusion Question: I tried to join a sample string in three ways, first entered by the code and then entered by user input. I got different results. #Why isn’t the output the same for these (in python 3.10.6): sampleString = ‘Fred’,’you need a nap! (your mother)’ ss1 = ‘ – ‘.join(sampleString) print(ss1), …

Total answers: 3

How to put values on a single raw from multiple columns in Pandas

How to put values on a single raw from multiple columns in Pandas Question: I have been scratching my head for days about this problem. Please, find below the structure of my input data and the output that I want. I color-coded per ID, Plot, Survey, Trial and the 3 estimation methods. In the output, …

Total answers: 1

Create new column by comparing existing column in a DataFrame

Create new column by comparing existing column in a DataFrame Question: I have the following DataFrame: datetime day_fetched col_a col_b 0 2023-01-02 12:00:00 2023-01-01 12:00:00 100 200 1 2023-01-02 12:00:00 2023-01-02 12:00:00 120 400 2 2023-01-03 12:00:00 2023-01-02 12:00:00 140 500 3 2023-01-03 12:00:00 2023-01-03 12:00:00 160 700 4 2023-01-04 12:00:00 2023-01-03 12:00:00 200 300 …

Total answers: 1

Strip quotes and spaces from a variable

Strip quotes and spaces from a variable Question: I want to create a variable [Word] that contains a word from a list of letters but does not include any brackets, spaces or commas. Here’s where i have gotten to: Letters = ["u", "i", "p","a","o","g", "h","j","k","l","z","x","v","b"] FirstLetter = -1 SecondLetter = ‘o’ ThirdLetter = ‘a’ FourthLetter …

Total answers: 1

Pandas, Cross summation with initial lag

Pandas, Cross summation with initial lag Question: I know something has been written about this but I don’t see a real solution other than writing line by line. I would like to do this: import pandas as pd df = pd.DataFrame([[1],[2],[4]], columns=[‘A’] ) B1 = A1 if A1>0 else 0 C1 = A1 B2 = …

Total answers: 1

Multi-index tuple join

Multi-index tuple join Question: I have the following column of a multiple index tuple in this form: df_incumbent_Q.columns Which looks like this: MultiIndex([(‘Cust Linehaul’, ‘2022Q2’), (‘Cust Linehaul’, ‘2022Q3’), (‘Cust Linehaul’, ‘2022Q4’), ( ‘Load Number’, ‘2022Q2’), ( ‘Load Number’, ‘2022Q3’), ( ‘Load Number’, ‘2022Q4’)], names=[None, ‘Quarter’]) I am trying to combine the columns name so that …

Total answers: 1

How to Print Python Lists as String

How to Print Python Lists as String Question: I would like to know how to print python lists as String instead of list. When I add the three lists I get the following result [‘a’, ‘b’, ‘c’, ‘d’, ‘0’, ‘1’, ‘!’, ‘#’] I want this output: abcd01!# import random letters = [‘a’, ‘b’, ‘c’, ‘d’, …

Total answers: 1

concat 2 df by time index without dropping rows

concat 2 df by time index without dropping rows Question: I convert the ‘time’ columns to index with the setindex function. I have 2 dfs, one with quarter hourly data and time as index. The second one contains hourly data with the identical index but hourly. Now I would like to concat the dfs so …

Total answers: 1