random

How to replace every NaN in a column with different random values using pandas?

风格不统一 提交于 2020-04-10 03:53:50
问题 I have been playing with pandas lately and I now I tried to replace NaN value inside a dataframe with different random value of normal distribution. Assuming I have this CSV file without header 0 0 343 1 483 2 101 3 NaN 4 NaN 5 NaN My expected result should be something like this 0 0 343 1 483 2 101 3 randomnumber1 4 randomnumber2 5 randomnumber3 But instead I got the following : 0 0 343 1 483 2 101 3 randomnumber1 4 randomnumber1 5 randomnumber1 # all NaN filled with same number My code so

How to replace every NaN in a column with different random values using pandas?

怎甘沉沦 提交于 2020-04-10 03:53:19
问题 I have been playing with pandas lately and I now I tried to replace NaN value inside a dataframe with different random value of normal distribution. Assuming I have this CSV file without header 0 0 343 1 483 2 101 3 NaN 4 NaN 5 NaN My expected result should be something like this 0 0 343 1 483 2 101 3 randomnumber1 4 randomnumber2 5 randomnumber3 But instead I got the following : 0 0 343 1 483 2 101 3 randomnumber1 4 randomnumber1 5 randomnumber1 # all NaN filled with same number My code so

How to replace every NaN in a column with different random values using pandas?

假如想象 提交于 2020-04-10 03:53:05
问题 I have been playing with pandas lately and I now I tried to replace NaN value inside a dataframe with different random value of normal distribution. Assuming I have this CSV file without header 0 0 343 1 483 2 101 3 NaN 4 NaN 5 NaN My expected result should be something like this 0 0 343 1 483 2 101 3 randomnumber1 4 randomnumber2 5 randomnumber3 But instead I got the following : 0 0 343 1 483 2 101 3 randomnumber1 4 randomnumber1 5 randomnumber1 # all NaN filled with same number My code so

Javascript - Generate random dark color

别来无恙 提交于 2020-04-09 18:04:52
问题 I have this method to generate me random colors for font: function getRandomRolor() { var letters = '0123456789ABCDEF'.split(''); var color = '#'; for (var i = 0; i < 6; i++) { color += letters[Math.round(Math.random() * 15)]; } return color; } The problem is that the font is always on white background, I want to generate dark colors. Is it possible? Thanks 回答1: You could use a custom function that takes a hex and darkens it by the percent lum . You can modify it to return whatever you want

Javascript - Generate random dark color

♀尐吖头ヾ 提交于 2020-04-09 18:03:44
问题 I have this method to generate me random colors for font: function getRandomRolor() { var letters = '0123456789ABCDEF'.split(''); var color = '#'; for (var i = 0; i < 6; i++) { color += letters[Math.round(Math.random() * 15)]; } return color; } The problem is that the font is always on white background, I want to generate dark colors. Is it possible? Thanks 回答1: You could use a custom function that takes a hex and darkens it by the percent lum . You can modify it to return whatever you want

How to access a random element in a dictionary in Swift

戏子无情 提交于 2020-04-08 09:22:11
问题 I got the following code: var myDic = [String: Customer]() let s1 = Customer("nameee", "email1") let s2 = Customer("nameee2", "email2") let s3 = Customer("nameee3", "email3") myDic[s1.name] = s1 myDic[s2.name] = s2 myDic[s3.name] = s3 How can I select a random element from the dictionary? I think I should use arc4random_uniform but couldn't find any documentation on it. 回答1: You have to cast some things around, but this seems to work. var dict:[String:Int] = ["A":123, "B": 234, "C": 345] let

How to access a random element in a dictionary in Swift

爱⌒轻易说出口 提交于 2020-04-08 09:21:55
问题 I got the following code: var myDic = [String: Customer]() let s1 = Customer("nameee", "email1") let s2 = Customer("nameee2", "email2") let s3 = Customer("nameee3", "email3") myDic[s1.name] = s1 myDic[s2.name] = s2 myDic[s3.name] = s3 How can I select a random element from the dictionary? I think I should use arc4random_uniform but couldn't find any documentation on it. 回答1: You have to cast some things around, but this seems to work. var dict:[String:Int] = ["A":123, "B": 234, "C": 345] let

Get random numbers in a specific range in java [duplicate]

雨燕双飞 提交于 2020-04-07 18:41:09
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Java: generating random number in a range I want to generate random numbers using java.util.Random(arg); The only problem is, the method can only take one argument, so the number is always between 0 and my argument. Is there a way to generate random numbers between (say) 200 and 500? 回答1: Random rand = new Random(seed); int random_integer = rand.nextInt(upperbound-lowerbound) + lowerbound; 回答2: First of, you

Get random numbers in a specific range in java [duplicate]

孤街醉人 提交于 2020-04-07 18:40:11
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Java: generating random number in a range I want to generate random numbers using java.util.Random(arg); The only problem is, the method can only take one argument, so the number is always between 0 and my argument. Is there a way to generate random numbers between (say) 200 and 500? 回答1: Random rand = new Random(seed); int random_integer = rand.nextInt(upperbound-lowerbound) + lowerbound; 回答2: First of, you

What's the best practice for getting a random DateTime between two date-times?

放肆的年华 提交于 2020-04-07 17:53:28
问题 I'm trying to randomize the value for a simple DateTime data field. I wish to get a random date/time between two date/times (e.g. min date/time and max date/time). So lets imagine I'm after a random date/time between 1/1/2000 10:00:00am and 1/1/2000 5:00:00pm . Also, this code will be used in a for loop, with 100 items ... meaning all 100 items will have random date/times between the min/max date/time period. Any ideas? 回答1: You could try using: var randomTest = new Random(); TimeSpan