import json
import geopandas as gpd
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import os
from datetime import datetime
from multiprocessing.pool import ThreadPool
from shapely.geometry import Polygon, MultiPolygon, shape
from shapely import GEOSException
import plotly.express as px
plt.rcParams['figure.figsize'] = [10, 5]
plotly_config = dict(
autosize=True,
#showlegend=False,
margin=dict(l=0, r=0, b=0, t=0, pad=0),
)
import seaborn as sns
sns.set_theme()
df = pd.read_csv('texty.csv') # , parse_dates=['Дата'], date_parser=parser) #, index_col='Дата', keep_date_col=True)
df['date'] = pd.to_datetime(df['Дата'], format='%d/%m/%Y', errors='coerce')
df = df.loc[df['date'].notnull()]
df = df.set_index('date').sort_index()
df['ракетний'].value_counts()
1.0 1254 2.0 1 Name: ракетний, dtype: int64
df['ракетний'].sum()
1256.0
df['missiles'] = pd.to_numeric(df['кількість ракет'], errors='coerce')
df['кількість ракет'].value_counts()
2 63 1 37 3 22 4 16 5 7 10 6 6 5 7 2 8 2 13 2 9 2 23 1 40 1 15 1 - 1 17 1 Name: кількість ракет, dtype: int64
#df.loc[df['missiles'].notnull(), 'missiles'].plot.bar(xticks=[])
fig = px.bar(
df.loc[df['missiles'].notnull(), 'missiles'], labels={'value': 'Missiles'}
).update_layout(**plotly_config).update_layout(showlegend=False)
fig.write_image("texty-missiles-daily.svg")
fig.show()
fig = px.bar(
df.loc[df['missiles'].notnull(), 'missiles'].resample('1w').sum(),
labels={'value': 'Missiles'}
).update_layout(**plotly_config).update_layout(showlegend=False)
fig.write_image("texty-missiles-weekly.svg")
fig.show()
fig = px.line(
df.loc[df['missiles'].notnull(), 'missiles'].resample('1d').sum().rolling(7).mean(),
labels={'value': 'Missiles'}
).update_layout(**plotly_config).update_layout(showlegend=False)
fig.write_image("texty-missiles-7day-rolling.svg")
fig.show()
df.loc[df['missiles'].notnull(), 'missiles'].plot.line(xticks=[])
<AxesSubplot: xlabel='date'>
df['barrages'] = np.where(df['missiles'] > 5, df['missiles'], np.nan)
df['barrages'].value_counts()
10.0 6 6.0 5 7.0 2 8.0 2 13.0 2 9.0 2 23.0 1 40.0 1 15.0 1 17.0 1 Name: barrages, dtype: int64
df.loc[df['barrages'].notnull(), 'barrages'].resample('1w').sum().plot.bar(xticks=[])
<AxesSubplot: xlabel='date'>
fig = px.bar(
df.loc[df['barrages'].notnull(), 'barrages'].resample('3d').sum(),
labels={'value': 'Missiles'},
#template='seaborn'
).update_layout(**plotly_config
).update_layout(showlegend=False
).update_traces(width=1000*60*60*24*3
)
#fig.write_image("texty-missiles-barrages.svg")
fig.show()