<jupyter_start><jupyter_text><NAME>, <NAME>, <NAME>> Indented block<jupyter_code>import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
df = pd.read_csv('https://raw.githubusercontent.com/nytimes/covid-19-data/master/us-states.csv')
df.head()
sd_df = df[df['state'] == 'South Dakota']

sd_df.head()
sd_df.shape
sd_df.tail()
#first death in SD
first_sd_death = sd_df[sd_df['deaths']!=0]
first_sd_death.head()
#total number of cases
sd_df['cases'].max()
#total number of deaths
sd_df['deaths'].max()
# not a correct way of calculating total count bcoz data is cumulative
sd_df['cases'].sum()
#new cases for SD
type(sd_df['cases'])

newcase = []
previuos_case = 0
for index, row in sd_df.iterrows():
  current_case = row['cases']
  newcase_count = current_case - previuos_case
  previuos_case = current_case
  newcase.append(newcase_count)
print(newcase_count)
sd_df['new_cases'] = newcase<jupyter_output>/usr/local/lib/python3.6/dist-packages/ipykernel_launcher.py:1: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  """Entry point for launching an IPython kernel.<jupyter_text>/usr/local/lib/python3.6/dist-packages/ipykernel_launcher.py:1: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame.Try using .loc[row_indexer,col_indexer] = value insteadSee the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.htmlreturning-a-view-versus-a-copy  """Entry point for launching an IPython kernel.<jupyter_code>sd_df.head(10)
sd_df['new_cases'].sum()
sd_cases = sd_df['cases']
sd_deaths = sd_df['deaths']
sd_dates = sd_df['date']
sd_new_cases = sd_df['new_cases']
type(sd_new_cases)
sd_df['new_cases'].plot(kind='line')
plt.title ('New Cases')
plt.xlabel('Time')
plt.ylabel('Cases')
plt.grid(axis='x')
plt.xticks(rotation=90)

plt.show()
sd_df.loc[:, 'date'] = pd.to_datetime(sd_df.loc[:, 'date'])

sd_df['month'] = sd_df['date'].dt.month

sd_df.head()
sd_df.loc[(sd_df['month'] == 8) |\
          (sd_df['month'] == 9)]
aug_dec = sd_df.loc[(sd_df['month'] == 8) |\
                    (sd_df['month'] == 12)].reset_index()

dates = aug_sep.loc[:, 'date']
new_cases = aug_sep.loc[:, 'new_cases']

plt.plot(dates, new_cases)
plt.title("August to September New Cases")
plt.xlabel('Dates')
plt.ylabel('New Cases')
plt.xticks(rotation=90)
plt.grid(axis='x')
plt.show()


plt.plot(days, new_cases)
plt.title("2020 New Cases")
plt.xlabel('Dates')
plt.ylabel('New Cases')
plt.xticks(rotation=90)
plt.grid(axis='x')
plt.show()
plt.bar(dates, new_cases)
plt.title("August to September New Cases")
plt.xlabel('Dates')
plt.ylabel('New Cases')
plt.xticks(rotation=90)
plt.show()
sd_cases = sd_df['cases']
sd_deaths = sd_df['deaths']
sd_dates = sd_df['date']
sd_new_cases = sd_df['new_cases']

days = range(len(sd_df.iloc[:, 0])) 

plt.plot(days, sd_cases)
plt.title('South Dakota Covid Total Cases')
plt.xlabel('Day   01-03-2020  to  03-05-2021')
plt.ylabel('Million Cases')
plt.show()



plt.plot(days, sd_df['deaths'], color='brown')
plt.title('South Dakota Covid Total Deaths')
plt.xlabel('January 2020 to January 2021')
plt.ylabel('Deaths')
plt.show()
plt.plot(days, sd_df['cases'], label='cases')

plt.plot(days, sd_df['deaths'], label='deaths')

plt.title('South Dakota Covid Total Cases & Deaths')
plt.xlabel('Day   01-03-2020  to  03-05-2021')
plt.ylabel('Million')
plt.legend()

plt.show()
sd_df.head()
days = range(len(sd_df.iloc[:,0]))
plt.plot(days, sd_new_cases)
plt.title('South Dakota Covid New Cases')
plt.xticks(rotation='vertical')
plt.ylabel('Cases')
plt.show()
plt.plot(days, sd_cases)
plt.title('South Dakota Covid Total Cases')
plt.xticks(rotation='vertical')
plt.ylabel('Total Cases')
plt.show()
plt.plot(days, sd_new_cases)
plt.title ('New Cases')
plt.xlabel('Time')
plt.ylabel('Cases')
plt.grid(axis='x')
plt.xticks(rotation=90)

plt.show()
plt.plot(days, sd_deaths)
plt.title ('New Cases')
plt.xlabel('Time')
plt.ylabel('Cases')
plt.grid(axis='x')
plt.xticks(rotation=90)

plt.show()
sd_df.head()
sd_df['month_year'] = sd_df['date'].dt.to_period('M')
sd_df
sd_df.groupby('month_year')['new_cases'].sum().reset_index()
sum_months = sd_df.groupby('month_year')['new_cases'].sum().reset_index()

sum_months.drop(index=10, inplace=True)

months = sum_months.loc[:, 'month_year'].dt.strftime('%Y-%m')
cases = sum_months.loc[:, 'new_cases']

plt.bar(months, cases)
plt.title("Total New Cases by Month")
plt.xlabel('Month')
plt.ylabel('Total New Cases')
plt.xticks(rotation=90)
plt.show()
mean_months = sd_df.groupby('month_year')['new_cases'].mean().reset_index()

mean_months.drop(index=10, inplace=True)

months = mean_months.loc[:, 'month_year'].dt.strftime('%Y-%m')
cases = mean_months.loc[:, 'new_cases']

plt.bar(months, cases)
plt.title("Daily Averge New Cases by Month")
plt.xlabel('Month')
plt.ylabel('Averge New Cases')
plt.xticks(rotation=90)
plt.show()
import seaborn as sns

sns.displot(sd_deaths, kde=True)\
.set(title='Daily New Cases Distribution')
plt.show()<jupyter_output><empty_output><jupyter_text>Last 30 Days<jupyter_code>sd_cases_30 = sd_df['cases'][-31:-1]
sd_deaths_30 = sd_df['deaths'] [-31:-1]
sd_dates_30 = sd_df['date'][-31:-1]
sd_new_cases_30 = sd_df['new_cases'][-31:-1]
plt.figure(figsize=(15,7))
plt.bar(x=sd_dates_30, height=sd_new_cases_30, color='red')
plt.xticks(rotation=90)
plt.title('New Cases: Last 30 Days')

plt.ylabel('New Cases')
plt.show()
plt.figure(figsize=(15,7))
plt.bar(x=sd_dates_30, height=sd_deaths_30, color='blue')
plt.xticks(rotation=90)
plt.title('Rise of Total Deaths: Last 30 Days')

plt.ylabel('Deaths')
plt.show()<jupyter_output><empty_output><jupyter_text>Comparing with different States<jupyter_code>states = ['Minnesota', 'North Dakota','Oklahoma', 'South Dakota', 'Wyoming']
plt.figure(figsize=(15,7))
for state in states:
  df_st = df[(df['state']==state) & (df['date']>='2020-08-07') & (df['date']<'2020-09-30')]
  plt.plot(df_st['date'],
           df_st['cases'],
           linewidth=2
           )
  plt.xticks(rotation=90)
plt.legend(states)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17951559284470475, 'fraction_numerical': 0.023587145797055564, 'mean_word_length': 6.245412844036697, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 21, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '325304', 'license': 'Apache-2.0', 'n_tokens_mistral': 2701, 'n_tokens_neox': 2457, 'n_words': 458, 'path': 'Python/Covid19_Group_Project.ipynb', 'repo_name': 'katiesalas/data_analytics_2', 'size': '6330'}