pandas concat generates nan values

I think there is problem with different index values, so where concat cannot align get NaN: aaa = pd.DataFrame([0,1,0,1,0,0], columns=[‘prediction’], index=[4,5,8,7,10,12]) print(aaa) prediction 4 0 5 1 8 0 7 1 10 0 12 0 bbb = pd.DataFrame([0,0,1,0,1,1], columns=[‘groundTruth’]) print(bbb) groundTruth 0 0 1 0 2 1 3 0 4 1 5 1 print (pd.concat([aaa, … Read more

sending NaN in json

json.dumps has an allow_nan parameter, which defaults to True. NaN, Infinity and -Infinity are not part of JSON, but they are standard in Javascript, so they’re commonly used extensions. If the recipient can’t handle them, set allow_nan=False. But then you’ll get ValueError when you try to serialise NaN.

Elegant way to create empty pandas DataFrame with NaN of type float

Simply pass the desired value as first argument, like 0, math.inf or, here, np.nan. The constructor then initializes and fills the value array to the size specified by arguments index and columns: >>> import numpy as np >>> import pandas as pd >>> df = pd.DataFrame(np.nan, index=[0, 1, 2, 3], columns=[‘A’, ‘B’]) >>> df A … Read more

Comparing numpy arrays containing NaN

For versions of numpy prior to 1.19, this is probably the best approach in situations that don’t specifically involve unit tests: >>> ((a == b) | (numpy.isnan(a) & numpy.isnan(b))).all() True However, modern versions provide the array_equal function with a new keyword argument, equal_nan, which fits the bill exactly. This was first pointed out by flyingdutchman; … Read more

Replace invalid values with None in Pandas DataFrame

Actually in later versions of pandas this will give a TypeError: df.replace(‘-‘, None) TypeError: If “to_replace” and “value” are both None then regex must be a mapping You can do it by passing either a list or a dictionary: In [11]: df.replace(‘-‘, df.replace([‘-‘], [None]) # or .replace(‘-‘, {0: None}) Out[11]: 0 0 None 1 3 … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)