missing-data

Function to change blanks to NA

巧了我就是萌 提交于 2019-11-27 07:44:23
问题 I'm trying to write a function that turns empty strings into NA. A summary of one of my column looks like this: a b 12 210 468 I'd like to change the 12 empty values to NA. I also have a few other factor columns for which I'd like to change empty values to NA, so I borrowed some stuff from here and there to come up with this: # change nulls to NAs nullToNA <- function(df){ # split df into numeric & non-numeric functions a<-df[,sapply(df, is.numeric), drop = FALSE] b<-df[,sapply(df, Negate(is

python format string unused named arguments [duplicate]

妖精的绣舞 提交于 2019-11-27 06:48:13
This question already has an answer here: partial string formatting 15 answers Let's say I have: action = '{bond}, {james} {bond}'.format(bond='bond', james='james') this wil output: 'bond, james bond' Next we have: action = '{bond}, {james} {bond}'.format(bond='bond') this will output: KeyError: 'james' Is there some workaround to prevent this error to happen, something like: if keyrror: ignore, leave it alone (but do parse others) compare format string with available named arguments, if missing then add If you are using Python 3.2+, use can use str.format_map() . For bond, bond : >>> from

Missing values in scikits machine learning

天涯浪子 提交于 2019-11-27 04:24:54
问题 Is it possible to have missing values in scikit-learn ? How should they be represented? I couldn't find any documentation about that. 回答1: Missing values are simply not supported in scikit-learn. There has been discussion on the mailing list about this before, but no attempt to actually write code to handle them. Whatever you do, don't use NaN to encode missing values, since many of the algorithms refuse to handle samples containing NaNs. The above answer is outdated; the latest release of

How to get Python to gracefully format None and non-existing fields [duplicate]

不打扰是莪最后的温柔 提交于 2019-11-27 04:03:39
This question already has an answer here: Leaving values blank if not passed in str.format 7 answers If I write in Python: data = {'n': 3, 'k': 3.141594, 'p': {'a': 7, 'b': 8}} print('{n}, {k:.2f}, {p[a]}, {p[b]}'.format(**data)) del data['k'] data['p']['b'] = None print('{n}, {k:.2f}, {p[a]}, {p[b]}'.format(**data)) I get: 3, 3.14, 7, 8 Traceback (most recent call last): File "./funky.py", line 186, in <module> print('{n}, {k:.2f}, {p[a]}, {p[b]}'.format(**data)) KeyError: 'k' Instead of an error message, how can I get Python to more gracefully format the None's and non existent fields? To

Insert missing time rows into a dataframe

落花浮王杯 提交于 2019-11-26 23:15:23
问题 Let's say I have a dataframe: df <- data.frame(group = c('A','A','A','B','B','B'), time = c(1,2,4,1,2,3), data = c(5,6,7,8,9,10)) What I want to do is insert data into the data frame where it was missing in the sequence. So in the above example, I'm missing data for time = 3 for group A, and time = 4 for Group B. I would essentially want to put 0's in the place of the data column. How would I go about adding these additional rows? The goal would be: df <- data.frame(group = c('A','A','A','A',

ggplot2: show missing value colour in legend

萝らか妹 提交于 2019-11-26 22:05:18
问题 Just wondering what is required so the colour for missing values is shown in the legend? Looking at example from the UseR! ggplot2 book, p94 p <- qplot(sleep_total, sleep_cycle, data=msleep, colour=vore) p + scale_colour_hue(na.value = "Black") p + scale_colour_hue("What does \nit eat?", na.value="Black", breaks=c("herbi", "carni", "omni", "insecti", NA), labels=c("plants", "meat", "both", "insects", "don't know")) the data point for vore=NA is shown in the plot but NA is not listed in the

java.lang.NoClassDefFoundError: android.support.v7.appcompat.R$styleable

江枫思渺然 提交于 2019-11-26 21:01:08
i am using terminal [not eclipse]. i got following exception error, while i use emulator.debug successfully and installd successfully. But emulator show Unfortunatly app has stop . Then i run $ adb logcat it will display following. java.lang.NoClassDefFoundError: android.support.v7.appcompat.R$styleable at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:107) at android.support.v7.app.ActionBarActivityDelegateICS.onCreate(ActionBarActivityDelegateICS.java:58) at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:98) at com.example

Pandas Dataframe: Replacing NaN with row average

白昼怎懂夜的黑 提交于 2019-11-26 18:22:35
问题 I am trying to learn pandas but i have been puzzled with the following please. I want to replace NaNs is a dataframe with the row average. Hence something like df.fillna(df.mean(axis=1)) should work but for some reason it fails for me. Am I missing anything please, something I'm doing wrong? Is is because its not implemented; see link here import pandas as pd import numpy as np ​ pd.__version__ Out[44]: '0.15.2' In [45]: df = pd.DataFrame() df['c1'] = [1, 2, 3] df['c2'] = [4, 5, 6] df['c3'] =

Multivariate LSTM with missing values

有些话、适合烂在心里 提交于 2019-11-26 16:43:42
问题 I am working on a Time Series Forecasting problem using LSTM. The input contains several features, so I am using a Multivariate LSTM. The problem is that there are some missing values, for example: Feature 1 Feature 2 ... Feature n 1 2 4 nan 2 5 8 10 3 8 8 5 4 nan 7 7 5 6 nan 12 Instead of interpolating the missing values, that can introduce bias in the results, because sometimes there are a lot of consecutive timestamps with missing values on the same feature, I would like to know if there

Leaving values blank if not passed in str.format

瘦欲@ 提交于 2019-11-26 16:41:30
问题 I've run into a fairly simple issue that I can't come up with an elegant solution for. I'm creating a string using str.format in a function that is passed in a dict of substitutions to use for the format. I want to create the string and format it with the values if they're passed and leave them blank otherwise. Ex kwargs = {"name": "mark"} "My name is {name} and I'm really {adjective}.".format(**kwargs) should return "My name is mark and I'm really ." instead of throwing a KeyError (Which is