Tag : Python

fig=plt.figure(figsize=(18,18)) ax = plt.gca() theRatios.plot(kind=’line’,x=’date’,y=’ratioCA’,color=’red’,ax=ax) theRatios.plot(kind=’line’,x=’date’,y=’ratioDailyCA’,color=’red’,linestyle=’dashed’, ax=ax) theRatios.plot(kind=’line’,x=’date’,y=’ratioON’,color=’blue’,ax=ax) theRatios.plot(kind=’line’,x=’date’,y=’ratioDailyON’,color=’blue’,linestyle=’dashed’, ax=ax) plt.title(‘COVID-19 case ratio of test (%)’) plt.xlabel(‘Date’) plt.ylabel(‘Percent(%)’) plt.grid(color=’k’, linestyle=’-‘, linewidth=0.1) ..

Read more

df2[‘date’] = df1[‘date’].values df2[‘hour’] = df1[‘hour’].values It’s better use inter join case.tail(3) caseCA caseON caseDaily CAcaseDailyON case_Date_province 2020-04-26 47864 15411 1598.0 498.0 2020-04-27 49499 15868 1635.0 457.0 2020-04-28 50982 16337 1483.0 469.0 test.tail(3) testCA testON testDailyCA testDailyON date_testing 2020-04-26 734824 229638 23570.0 12020.0 2020-04-27 765056 242188 30232.0 12550.0 2020-04-28 787612 253040 22556.0 10852.0 case_test = ..

Read more

import pandas as pd from plotly.offline import iplot import cufflinks cufflinks.go_offline() # Set global theme cufflinks.set_config_file(world_readable=True, theme=’pearl’) fig=df.iplot(asFigure=True, mode=’lines+markers’, size=6, secondary_y = ‘Increase’, secondary_y_title=’Increase’, xTitle=’Date’, yTitle=’Cases’, title=’Projected COVID-19 Cases in South Korea’, theme=’solar’) fig.show() import pandas as pd import chart_studio.plotly as py from ipywidgets import interact, interact_manual import cufflinks as cf @interact def plot_ProjectedSouthKereaCOVID19(): fig=output.iplot(asFigure=True, ..

Read more

df.orderBy(‘colname1′,’colname2’,ascending=False) from pyspark.sql.functions import sort_array df = spark.createDataFrame([([2, 1, 3],),([1],),([],)], [‘data’]) df.show() +———+ | data| +———+ |[2, 1, 3]| | [1]| | []| +———+ df0=spark.createDataFrame(df.select(sort_array(df.data).alias(‘r’)).collect(),[‘data’] df0.show() +———+ | data| +———+ |[1, 2, 3]| | [1]| | []| +———+ df1=spark.createDataFrame(df.select(sort_array(df.data, asc=False).alias(‘r’)).collect(),[‘data’]) df1.show() +———+ | data| +———+ |[3, 2, 1]| | [1]| | []| +..

Read more

By columns df.sort_values(by=[‘col1’]) df.sort_values(by=[‘col1’, ‘col2′]) df.sort_values(by=’col1′, ascending=False) df.sort_values(by=’col1′, ascending=False, na_position=’first’) By rows 0 col1 col2 col3 row1 222 16 23 row2 333 31 11 row3 444 34 11 df.sort_values(by=’row2′,axis=1) output: 0 col1 col2 col3 row1 23 16 222 row2 11 31 333 row3 11 34 444 df.sort_values(by=’row2′,axis=1,ascending=False) output: 0 col1 col2 col3 row1 222 16 ..

Read more

import pandas as pd import numpy as np # model from lmfit import Minimizer, Parameters, report_fit #plot import chart_studio.plotly as py import ipywidgets as widgets from ipywidgets import interact, interact_manual import cufflinks as cf theCountry=’Canada’ threshhold=10 theData=confirmed_series_21[confirmed_series_21[theCountry]>threshhold] data=theData[theCountry] start_date= data.index[0] end_date= data.index[-1] dateData=pd.date_range(start=start_date,end=end_date) forecastDays=60 dateForecast= pd.date_range(start=end_date,periods=forecastDays+1)[1:] dateObsForecast=dateData.append(dateForecast) #dateObsForecast # define objective function: returns the array ..

Read more

list0=[‘Confirmed Cases’,’Recovered Cases’, ‘Deaths Reported’,’Active Cases’] def Reverse(lst): return [ele for ele in reversed(lst)] list1=Reverse(list0) list1 [‘Active Cases’, ‘Deaths Reported’, ‘Recovered Cases’, ‘Confirm..

Read more

Replace NaN in dataframe with ” df_confirmed = df_confirmed.replace(np.nan, ”, regex=True) Fill NaN with another column Day col1 col2 1 1 a 2 NaN b df[‘col1’].fillna(df[‘col2’]) Day col1 col2 1 1 a 2 b b Replace NaN with 0 df[‘DataFrame Column’] = df[‘DataFrame Column’].fillna(0) Replace all NaN in df df..

Read more

import os path=’COVID-19-master/csse_covid_19_data/csse_covid_19_time_series’ confirmed_fn=os.path.join(path,’time_series_covid19_confirmed_global.csv’) confirmed_fn ‘COVID-19-master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_g..

Read more