Poprawki i trim

This commit is contained in:
Jan Nowak 2021-05-26 17:22:26 +02:00
parent 2d7bc98357
commit 15d72368aa
2 changed files with 33 additions and 9 deletions

View File

@ -26,7 +26,7 @@ cov <- read.csv("proj2/max-covid.csv", header = TRUE)
#df <- data.frame(as.Date(cov$date, format="%Y-%m-%d"), cov$iso_code, cov$total_cases)
df <- data.frame(as.Date(cov$date), cov$iso_code, cov$total_cases)
colnames(df) <- c('date', 'iso', 'total_cases')
#colnames(df) <- c('date', 'iso', 'total_cases')
#df$date = format(df$date, "%Y-%m")
@ -51,16 +51,17 @@ wmap_df <- left_join(wmap_df, df, by = c('id'='cov.iso_code'))
ggplot(data=wmap_df, frame = date) +
geom_polygon(aes(x = long, y = lat, group = group, fill=cov.total_cases), color="gray90") +
scale_fill_viridis(name="Cases", begin = 0, end = 1, limits = c(casesmin,casesmax), na.value="gray99") +
scale_fill_viridis(name="Zachorowania", na.value="white") +
theme_void() +
guides(fill = guide_colorbar(title.position = "top")) +
labs(title = "") +
theme( legend.position = c(.5, .08),
legend.direction = "horizontal",
legend.title.align = 0,
legend.key.size = unit(1.3, "cm"),
legend.title=element_text(size=17),
legend.text=element_text(size=13) )
labs(title = "Liczba zachorowań w dniu 31.05.2021")
#+
# theme( legend.position = c(.5, .08),
# legend.direction = "horizontal",
# legend.title.align = 0,
# legend.key.size = unit(1.3, "cm"),
# legend.title=element_text(size=17),
# legend.text=element_text(size=13) )
#+
# transition_time(date)

23
proj2/trim.py Normal file
View File

@ -0,0 +1,23 @@
import pandas as pd
import numpy as np
data = pd.read_csv('owid-covid-data.csv')
df = data[['iso_code', 'date', 'total_cases']]
df['date']=pd.to_datetime(df['date'], format='%Y-%m-%d')
df.info()
iso = df.iso_code.unique()
df2 = pd.DataFrame(columns=['iso_code', 'date', 'total_cases'])
df3 = pd.DataFrame(columns=['iso_code', 'date', 'total_cases'])
for country in iso:
country_v = df.loc[df['iso_code'] == country]
months = country_v.set_index('date').groupby(pd.Grouper(freq='M')).max()
i=0
for index, month in months.iterrows():
#df2.append(month)
if i==months.shape[0]-1:
df3 = df3.append({'iso_code': month['iso_code'], 'date': month.name, 'total_cases': month['total_cases']}, ignore_index=True)
df2 = df2.append({'iso_code': month['iso_code'], 'date': month.name, 'total_cases': month['total_cases']}, ignore_index=True)
i += 1
df2.to_csv('month-covid.csv', sep=',')
df3.to_csv('max-covid.csv', sep=',')