time-series

Stick Plot for wind speed and direction data in ggplot

只谈情不闲聊 提交于 2021-02-05 11:30:58
问题 I'd like to plot a stick plot for wind speed/ direction data similar to this: https://www.researchgate.net/figure/Stick-plot-of-mean-daily-wind-speed-and-direction-measured-at-Valentia-Island-from_fig5_226577448 I've found a good plot in the excelent oce package, but I'd like to make this same kind of plot using ggplot (or plotley). WindSpeed<-c(1,2,3,5,7,2,3,4,5,6,7,8) WindDir<-c(180,90,320,200,350,10,270,50,9,100,110,129) TimeStamp<-c("2018-01-02 01:00","2018-01-02 02:00","2018-01-02 03:00"

Stick Plot for wind speed and direction data in ggplot

偶尔善良 提交于 2021-02-05 11:30:22
问题 I'd like to plot a stick plot for wind speed/ direction data similar to this: https://www.researchgate.net/figure/Stick-plot-of-mean-daily-wind-speed-and-direction-measured-at-Valentia-Island-from_fig5_226577448 I've found a good plot in the excelent oce package, but I'd like to make this same kind of plot using ggplot (or plotley). WindSpeed<-c(1,2,3,5,7,2,3,4,5,6,7,8) WindDir<-c(180,90,320,200,350,10,270,50,9,100,110,129) TimeStamp<-c("2018-01-02 01:00","2018-01-02 02:00","2018-01-02 03:00"

pandas resample to get monthly average with time series data

帅比萌擦擦* 提交于 2021-02-05 10:54:06
问题 I'm using the time series dataset from tableau (https://community.tableau.com/thread/194200), containing daily furniture sales, and I want to resample to get average monthly sales. And I tried using resample in Pandas to get monthly mean: There are four days in January selling furniture, and there is no sales in the rest of Jan. Order Date Sales ... 2014/1/6 2573.82 2014/1/7 76.728 2014/1/16 127.104 2014/1/20 38.6 ... y_furniture = furniture['Sales'].resample('MS').mean() I want the result to

add horizontal limit line to time series plot in python

对着背影说爱祢 提交于 2021-02-05 10:50:13
问题 I want to add horizontal upper and lower limit line for Temparature timeseries plot. Lets say upper limit line at 30 and lower limit line at 10. df3.plot(x="Date", y=["Temp.PM", "Temp.AM"],figsize=(20,8)) 回答1: I think this solution can help you import matplotlib.pyplot as plt %matplotlib inline df3.plot(x="Date", y=["Temp.PM", "Temp.AM"],figsize=(20,8)) plt.axhline(30) plt.axhline(10) 回答2: plt.plot(df3['Date'], df3[["Temp.PM", "Temp.AM"]]) plt.axhline(30, color='r') plt.axhline(10, color='b')

Adding row shifting in pandas dataframe

你离开我真会死。 提交于 2021-02-05 07:54:30
问题 I have a pandas df , which I created by using shift() function iterating through the original df : for i in range(2, 4): df["lag_{}".format(i)] = df.x.shift(i) So there will be actual x column and lag2-lag10 columns with shifted x values. I have trained this dataset for the regression model to make one-step forward prediction. Would like to add the new row in the end of the dataframe with nan value for x and shifted values from the last position to be able to use these new lags for fitting

Pandas: Fill missing values using last available

荒凉一梦 提交于 2021-02-05 06:45:06
问题 I have a dataframe as follows: A B zDate 01-JAN-17 100 200 02-JAN-17 111 203 03-JAN-17 NaN 202 04-JAN-17 109 205 05-JAN-17 101 211 06-JAN-17 105 NaN 07-JAN-17 104 NaN What is the best way, to fill the missing values, using last available ones? Following is the intended result: A B zDate 01-JAN-17 100 200 02-JAN-17 111 203 03-JAN-17 111 202 04-JAN-17 109 205 05-JAN-17 101 211 06-JAN-17 105 211 07-JAN-17 104 211 回答1: Use ffill function, what is same as fillna with method ffill : df = df.ffill()

Make prediction for each group differently

瘦欲@ 提交于 2021-02-05 06:41:09
问题 I have dataset that looks like this: Category Weekly_Date a b <chr> <date> <dbl> <dbl> 1 aa 2018-07-01 36.6 1.4 2 aa 2018-07-02 5.30 0 3 bb 2018-07-01 4.62 1.2 4 bb 2018-07-02 3.71 1.5 5 cc 2018-07-01 3.41 12 ... ... ... ... ... I fitted linear regression for each group separately: fit_linreg <- train %>% group_by(Category) %>% do(model = lm(Target ~ Unit_price + Unit_discount, data = .)) Now I have different models for each category: aa model1 bb model2 cc model3 So, I need to apply each

Matplotlib dates YearLocator with odd intervals

≡放荡痞女 提交于 2021-02-05 05:59:45
问题 Right now I have a working bit of code that formats to my specification when my time series begin at the start of a decade (i.e. 1990, 2000, 2010,etc.), but I don't know how to adapt my code to have the correct formatting when my time series begins at a year that isn't even (i.e. 1993). import pandas as pd import matplotlib.pyplot as plt from matplotlib import dates def format_xaxis(fig): years = dates.YearLocator(10,month=1,day=1) years1=dates.YearLocator(2,month=1,day=1) dfmt = dates

Matplotlib dates YearLocator with odd intervals

别说谁变了你拦得住时间么 提交于 2021-02-05 05:59:32
问题 Right now I have a working bit of code that formats to my specification when my time series begin at the start of a decade (i.e. 1990, 2000, 2010,etc.), but I don't know how to adapt my code to have the correct formatting when my time series begins at a year that isn't even (i.e. 1993). import pandas as pd import matplotlib.pyplot as plt from matplotlib import dates def format_xaxis(fig): years = dates.YearLocator(10,month=1,day=1) years1=dates.YearLocator(2,month=1,day=1) dfmt = dates

How to repeat 1000 times this random walk simulation in R?

﹥>﹥吖頭↗ 提交于 2021-02-05 05:19:25
问题 I'm simulating a one-dimensional and symmetric random walk procedure: y[t] = y[t-1] + epsilon[t] where white noise is denoted by epsilon[t] ~ N(0,1) in time period t . There is no drift in this procedure. Also, RW is symmetric, because Pr(y[i] = +1) = Pr(y[i] = -1) = 0.5 . Here's my code in R: set.seed(1) t=1000 epsilon=sample(c(-1,1), t, replace = 1) y<-c() y[1]<-0 for (i in 2:t) { y[i]<-y[i-1]+epsilon[i] } par(mfrow=c(1,2)) plot(1:t, y, type="l", main="Random walk") outcomes <- sapply(1