fill

python pandas dataframe : fill nans with a conditional mean

无人久伴 提交于 2020-04-12 10:49:30
问题 I have the following dataframe: import numpy as np import pandas as pd df = pd.DataFrame(data={'Cat' : ['A', 'A', 'A','B', 'B', 'A', 'B'], 'Vals' : [1, 2, 3, 4, 5, np.nan, np.nan]}) Cat Vals 0 A 1 1 A 2 2 A 3 3 B 4 4 B 5 5 A NaN 6 B NaN And I want indexes 5 and 6 to be filled with the conditional mean of 'Vals' based on the 'Cat' column, namely 2 and 4.5 The following code works fine: means = df.groupby('Cat').Vals.mean() for i in df[df.Vals.isnull()].index: df.loc[i, 'Vals'] = means[df.loc[i

python pandas dataframe : fill nans with a conditional mean

自作多情 提交于 2020-04-12 10:47:45
问题 I have the following dataframe: import numpy as np import pandas as pd df = pd.DataFrame(data={'Cat' : ['A', 'A', 'A','B', 'B', 'A', 'B'], 'Vals' : [1, 2, 3, 4, 5, np.nan, np.nan]}) Cat Vals 0 A 1 1 A 2 2 A 3 3 B 4 4 B 5 5 A NaN 6 B NaN And I want indexes 5 and 6 to be filled with the conditional mean of 'Vals' based on the 'Cat' column, namely 2 and 4.5 The following code works fine: means = df.groupby('Cat').Vals.mean() for i in df[df.Vals.isnull()].index: df.loc[i, 'Vals'] = means[df.loc[i

python pandas dataframe : fill nans with a conditional mean

霸气de小男生 提交于 2020-04-12 10:41:30
问题 I have the following dataframe: import numpy as np import pandas as pd df = pd.DataFrame(data={'Cat' : ['A', 'A', 'A','B', 'B', 'A', 'B'], 'Vals' : [1, 2, 3, 4, 5, np.nan, np.nan]}) Cat Vals 0 A 1 1 A 2 2 A 3 3 B 4 4 B 5 5 A NaN 6 B NaN And I want indexes 5 and 6 to be filled with the conditional mean of 'Vals' based on the 'Cat' column, namely 2 and 4.5 The following code works fine: means = df.groupby('Cat').Vals.mean() for i in df[df.Vals.isnull()].index: df.loc[i, 'Vals'] = means[df.loc[i

Fill area between multiple lines in plot

做~自己de王妃 提交于 2020-01-30 10:56:16
问题 I have got a plot with 3 lines as follows: a = data.frame(time = c(1:100), x = rnorm(100)) b = data.frame(time = c(1:100), y = rnorm(100)) c = data.frame(time = c(1:100), z = rnorm(100)) plot(a$time, a$x, type = 'l') lines(b$time, b$y, type = 'l') lines(c$time, c$z, type = 'l') I need to fill the area between the lowest and maximum value of the lines so that I get a unique polygon of a given colour. I know about the polygon function but I do not know how to use it in this case. Any suggestion

Swift how to fill in overlay with a new color

筅森魡賤 提交于 2020-01-17 05:48:11
问题 I am having trouble filling in the overlay. I would like to use a new color. Thanks for the help in advance. func addBoundry() { var points=[CLLocationCoordinate2DMake(39.02, -76.9),CLLocationCoordinate2DMake(38.97, -76.9),CLLocationCoordinate2DMake(38.97, -77),CLLocationCoordinate2DMake(39.02, -77)] let polygon = MKPolygon(coordinates: &points, count: points.count) mapView.addOverlay(polygon) } let regionRadius: CLLocationDistance = 1000 func centerMapOnLocation(location: CLLocation) { let

Gnuplot : How to fill space between dataset and graph

て烟熏妆下的殇ゞ 提交于 2020-01-15 03:26:06
问题 I have a data file with X,Y scattered data and I want to fill somehow (pattern, solid transparent, whatever) the space outside of those points. I tried with filledcurves closed but it fills the inside, not the outside Is there a way to fill the space without separating the data points into several lines and set fill above/below the axis? Thank you 回答1: Would it be an option to post process the plots with Imagemagick? Then you could produce two images, one with transparency, and combine them

Fill several sections below a curve of data in Gnuplot

我是研究僧i 提交于 2020-01-13 04:29:09
问题 I have a set of points "data" defining a curve that I want to plot with bezier smooth. So I want to fill the area below that curve between some pairs of x values. If I only had one pair of x values it's not that difficult because I define a new set of data and plot it with filledcu. Example: The problem is that I want to do that several times in the same plot. Edit: Minimal working example: #!/usr/bin/gnuplot set terminal wxt enhanced font 'Verdana,12' set style fill transparent solid 0.35

Fill several sections below a curve of data in Gnuplot

跟風遠走 提交于 2020-01-13 04:29:07
问题 I have a set of points "data" defining a curve that I want to plot with bezier smooth. So I want to fill the area below that curve between some pairs of x values. If I only had one pair of x values it's not that difficult because I define a new set of data and plot it with filledcu. Example: The problem is that I want to do that several times in the same plot. Edit: Minimal working example: #!/usr/bin/gnuplot set terminal wxt enhanced font 'Verdana,12' set style fill transparent solid 0.35

how to fill images using progressbar in android

自古美人都是妖i 提交于 2020-01-12 10:22:36
问题 I am working on a project and it requires to fill the image. means i want to use the image shape as a progress bar. I don't get any idea of how to use custom progress-bar. here is an image and its an image-button. So this is when progress is 100%: and this for 0% progress: 回答1: You need to learn about drawable resources. Drawable Resources | Android Developers You can do this with a Layer List and a Clip Drawable. First, let's talk about level. Every drawable has a level that goes from 0 to

how to fill images using progressbar in android

走远了吗. 提交于 2020-01-12 10:22:03
问题 I am working on a project and it requires to fill the image. means i want to use the image shape as a progress bar. I don't get any idea of how to use custom progress-bar. here is an image and its an image-button. So this is when progress is 100%: and this for 0% progress: 回答1: You need to learn about drawable resources. Drawable Resources | Android Developers You can do this with a Layer List and a Clip Drawable. First, let's talk about level. Every drawable has a level that goes from 0 to