null

Assign a unique value to consecutive null values untill a non value

Assign a unique value to consecutive null values untill a non value Question: I want to apply a function that does the cumulative count of null values. The closest solution I came to was this: import pandas as pd import numpy as np # create the column col = pd.Series([1, 2, np.nan, np.nan, 3, 4, …

Total answers: 2

Pandas pull rows where any column contains certain strings

Pandas pull rows where any column contains certain strings Question: I’m trying to return rows where any of my columns contain any of the words in a word list. Let’s say word_list = [‘Synthetic’, ‘Advanced or Advantage/Excellence’]. I’ve tried the following code df[df.apply(‘ ‘.join, 1).str.contains(‘|’.join(word_list))]. The problem is some of my columns contain null values, …

Total answers: 1

Write to CSV the last non-null row from pandas dataframe?

Write to CSV the last non-null row from pandas dataframe? Question: This writes all records, including null PbRatios. I would like to write the last non-null record only. When I add df[df.asOfDate == df.asOfDate.max()].to_csv, it gets the last record, which is always null. import pandas as pd from yahooquery import Ticker symbols = [‘AAPL’,’GOOG’,’MSFT’,’NVDA’] header …

Total answers: 2

Column with column names for nulls in row

Column with column names for nulls in row Question: I want to add new column "Null_Values" in PySpark dataframe as below =======================================================| ID | Maths | Science | English | NUll_Values | =======================================================| 11 | 80 | NULL | 89 | Science | 12 | NULL | NULL | 89 | Maths,Science | 13 | …

Total answers: 1

Replace null with empty string when writing Spark dataframe

Replace null with empty string when writing Spark dataframe Question: Is there a way to replace null values in a column with empty string when writing spark dataframe to file? Sample data: +—————-+——————+ | UNIQUE_MEM_ID| DATE| +—————-+——————+ | 1156| null| | 3787| 2016-07-05| | 1156| null| | 5064| null| | 5832| null| | 3787| null| …

Total answers: 2

Remove row with null value from pandas data frame

Remove row with null value from pandas data frame Question: I’m trying to remove a row from my data frame in which one of the columns has a value of null. Most of the help I can find relates to removing NaN values which hasn’t worked for me so far. Here I’ve created the data …

Total answers: 5

Python: How to convert Pyspark column to date type if there are null values

Python: How to convert Pyspark column to date type if there are null values Question: In pyspark, I have a dataframe that has dates that get imported as strings. There are null values in these dates-as-strings columns. I’m trying to convert these columns into date type columns, but I keep getting errors. Here’s a small …

Total answers: 2

Pandas – check if ALL values are NaN in Series

Pandas – check if ALL values are NaN in Series Question: I have a data series which looks like this: print mys id_L1 2 NaN 3 NaN 4 NaN 5 NaN 6 NaN 7 NaN 8 NaN I would like to check is all the values are NaN. My attempt: pd.isnull(mys).all() Output: True Is this …

Total answers: 3

Python pandas apply function if a column value is not NULL

Python pandas apply function if a column value is not NULL Question: I have a dataframe (in Python 2.7, pandas 0.15.0): df= A B C 0 NaN 11 NaN 1 two NaN [‘foo’, ‘bar’] 2 three 33 NaN I want to apply a simple function for rows that does not contain NULL values in a …

Total answers: 7