concatenation

Row-wise concatenation in pandas

Row-wise concatenation in pandas Question: How can I concat strings in a pandas Dataframe row-wise and create a new row out of it? Here for example, I want to create a new row by concatenating the values in all cells of index 3 and 4. So the desired row would look like this: pd.Series([Brand Model, …

Total answers: 1

Pandas merge two dataframes horizontally

Pandas merge two dataframes horizontally Question: I am dealing with a problem like this: mydata_old | x | y | |—–|——| | 1 | 10 | | 2 | 15 | | 3 | 12 | | 4 | 21 | mydata_new | x | y | |—–|——| | 4 | 20 | | 5 …

Total answers: 1

Concatenate columns ignoring duplicates with pandas

Concatenate columns ignoring duplicates with pandas Question: does anyone know how to concatenate multiple columns excluding duplicated values? I’m a student of python, this is my first project and I have a problem I have a dataset like this one: each number represents a column from my dataframe df = {‘col1’: [‘a’,’b’,’a’,’c’], ‘col2′: ["","",’a’,”], ‘col3′: …

Total answers: 2

first argument must be an iterable of pandas objects, you passed an object of type "Series"

first argument must be an iterable of pandas objects, you passed an object of type "Series" Question: I have the following dataframe: s = df.head().to_dict() print(s) {‘BoP transfers’: {1998: 12.346282212735618, 1999: 19.06438060024298, 2000: 18.24888031473687, 2001: 24.860019912667006, 2002: 32.38242225822908}, ‘Current balance’: {1998: -6.7953, 1999: -2.9895, 2000: -3.9694, 2001: 1.1716, 2002: 5.7433}, ‘Domestic demand’: {1998: 106.8610389799729, 1999: …

Total answers: 1

How to concatenate columns in CSV file using Python and Count the Total per UniqueID?

How to concatenate columns in CSV file using Python and Count the Total per UniqueID? Question: This question have been asked multiple times in this community but I couldn’t find the correct answers since I am beginner in Python. I got 2 questions actually: I want to concatenate 3 columns (A,B,C) with its value into …

Total answers: 2

Space de-limited results, errors when Concatenating 2 columns

Space de-limited results, errors when Concatenating 2 columns Question: the code I’m running gives results that are space de-liminated. This creates a problem with my sector column which gives a result of Communication Services. It creates 1 column for Communication and another column for Services where I need 1 column saying Communication Services. I have …

Total answers: 1

How to create a pandas dataframe from a txt file with comments?

How to create a pandas dataframe from a txt file with comments? Question: I need to create a pandas dataframe based on 4 txt files with comments (to skip while reading) based on the following structure: # Moteur conçu par le Poly Propulsion Lab (PPL) nom=Tondeuse # Propriétés générales hauteur=0.5 masse=20.0 prix=110.00 # Propriétés du …

Total answers: 2

How do you split an array into specific intervals in Num.py for Python?

How do you split an array into specific intervals in Num.py for Python? Question: The question follows a such: x = np.arange(100) Write Python code to split the following array at these intervals: 10, 25, 45, 75, 95 I have used the split function and unable to get at these specific intervals, can anyone enlighten …

Total answers: 1

Add data to DataFrame by function

Add data to DataFrame by function Question: thats my function: import pandas as pd shopping_list = pd.DataFrame() shopping_list = shopping_list.assign(Order=0, Type=0, Price=0, Quantity=0) def add_item(order: str, type_transaction: str, price: float, quantity: int, shopping_list=shopping_list): new_item_data = pd.DataFrame({"Order": [order], "Type": [type_transaction], "Price": [price], "Quantity": [quantity]}) return pd.concat([shopping_list, new_item_data], ignore_index=True) add_item(order="Buy", type_transaction="Add", price=20.0, quantity=100) add_item(order="Sell", type_transaction="Add", price=25.0, quantity=200) …

Total answers: 2

Why is pandas adding new columns to my new excel file

Why is pandas adding new columns to my new excel file Question: I am trying to concatenate two excel files with the same column names together, but there seems to be a problem as there are new empty columns/spaces being added to my new excel file, and i don’t know why. I used pd.concat() function …

Total answers: 1