dataframe

Remove empty strings from a list of strings on each row in a pandas dataframe

Remove empty strings from a list of strings on each row in a pandas dataframe Question: I have a pandas dataframe and one of the columns contains a list of strings e.g: [”, ‘Hello’, ‘The house is warm’, ”, ‘What time is it’] The strings are different for each row of the dataframe but all …

Total answers: 1

group column values with difference of 3(say) digit in python

group column values with difference of 3(say) digit in python Question: I am new in python, problem statement is like we have below data as dataframe df = pd.DataFrame({‘Diff’:[1,1,2,3,4,4,5,6,7,7,8,9,9,10], ‘value’:[x,x,y,x,x,x,y,x,z,x,x,y,y,z]}) Diff value 1 x 1 x 2 y 3 x 4 x 4 x 5 y 6 x 7 z 7 x 8 x 9 …

Total answers: 1

'DataFrame' object does not support item assignment

'DataFrame' object does not support item assignment Question: I imported a df into Databricks as a pyspark.sql.dataframe.DataFrame. Within this df I have 3 columns (which I have verified to be strings) that I wish to concatenate. I have tried to use a simple "+" function first, eg. df["fullname"] = df["firstname"] + df["middlename"] + df["lastname"] But …

Total answers: 2

How to convert text into structured data, taking into account missing fields, in Python?

How to convert text into structured data, taking into account missing fields, in Python? Question: First, apologies if this sounds too basic. I have the following semi-structured data in text format, I need to parse these into a structured format: example: Name Alex Address 14 high street London Color blue red Name Bob Color black …

Total answers: 2

Change dates to quarters in JSON file Python

Change dates to quarters in JSON file Python Question: I’m trying to convert the dates inside a JSON file to their respective quarter and year. My JSON file is formatted below: { "lastDate": { "0": "11/22/2022", "1": "10/28/2022", "2": "10/17/2022", "7": "07/03/2022", "8": "07/03/2022", "9": "06/03/2022", "18": "05/17/2022", "19": "05/08/2022", "22": "02/03/2022", "24": "02/04/2022" } …

Total answers: 2

How to write dataframe to csv for max date rows only (filter for max date rows)?

How to write dataframe to csv for max date rows only (filter for max date rows)? Question: How do I get the df.to_csv to write only rows with the max asOfDate? So that each symbol below will only one row? import pandas as pd from yahooquery import Ticker symbols = [‘AAPL’,’GOOG’,’MSFT’] #There are 75,000 symbols …

Total answers: 1

Pandas – Dataframe dates subtraction

Pandas – Dataframe dates subtraction Question: I am dealing with a dataframe like this: mydata[‘TS_START’] 0 2022-11-09 00:00:00 1 2022-11-09 00:00:30 2 2022-11-09 00:01:00 3 2022-11-09 00:01:30 4 2022-11-09 00:02:00 … I would like to create a new column where: mydata[‘delta_t’] 0 2022-11-09 00:00:30 – 2022-11-09 00:00:00 1 2022-11-09 00:01:00 – 2022-11-09 00:00:30 2 2022-11-09 …

Total answers: 1