Stats for Views in 2020

Well, this is my last post in this year.

I’ve just downloaded my stats from WordPress to get information about how many people form which Country visit my side in 2020.

Wit matplotlib in Python I can present some data on the diagrams. First, need to install lib in PyCharm: pip install matplotlib.

Then try to read data from file and present the visalisation.

df = pd.read_csv('sunsetgirlsql_countryviews_12312020.csv', sep=',')
df = df.sort_values('Views', ascending=False)
print(df)
Visualisation
#Visualisation
# Filtering Views Value:between 10 to 1000.
df = df[(df['Views'] >= 10) & (df['Views'] <= 1000)]
# X-axis:
x = df['Views']
# Y-axis:
y = df['Country']
# Size of the figure (in inches).
plt.figure(figsize=(20,7))

#Scatter
plt.scatter(x, y,s = 100, color = 'violet',
            alpha = 0.8, marker = '.', 
            edgecolors='green')
# X-axis label.
plt.xlabel('Views', fontsize = 16)
# Y-axis label.
plt.ylabel('Country', fontsize = 16)

# Title of the plot.
plt.title('Heart4DataScience Mostly View\nby Country in 2020', 
          fontsize = 20)
# Grid
plt.grid(axis='y')

# Displays the plot.
plt.show()
# Clears the current figure contents.
plt.clf()

Wave goodbye to the old and embrace the new full of hope, dream, and ambition. Wishing you a happy new year full of happiness!

DataFrames

Date ranges

import pandas as pd

dates1 = pd.date_range('2020-01-01', periods=6,freq="D")
dates2 = pd.date_range('2020-01-01', periods=4,freq="M")
dates3 = pd.date_range('2020-01-01', periods=2,freq="Y")
print(dates1)
print(dates2)
print(dates3)
results

DataFrame creating

# Creating a DataFrame by passing a numpy array, with an index and labeled columns:
df = pd.DataFrame(np.random.randn(6,4),
                  index=dates1,
                  columns=['I','II','III','IV'])
print(df)
df result

DataFrame functions

# Data Parts
print('first row od dataframe:',df.head(1))
print('part of dataframe:',df.tail(3))

# Describe shows a quick statistic summary of your data
print('stats for dataframe:',df.describe())

# Sorting & Transposition
df2 = df.sort_index(axis=1, ascending=False)
print('transposition for sorted dataframe:',df2.T)
print('sorted dataframe no.2:',df2.sort_values(by="II"))

DataFrames selection methods

# Creating a DataFrame by passing a numpy array, 
#with an index and labeled columns:

dates = pd.date_range('20210101', periods=4)
df3 = pd.DataFrame(np.random.randn(4,3), 
index=dates, columns=list('XYZ'))
print(df3)

# Selection methods
print('values for X:')
print(df3['X'])
print('part of:')
print(df3[2:4])
print('Selection by Label:')
print(df3.loc[dates[3]])
print('get all the indexes and only two columns:')
print(df3.loc[:,['X','Y']])
print('if you want particular value')
print(df3.loc[dates[0],'X'])
print('Selection by Position:')
print(df3.iloc[3])
print(df3.iloc[3:4,0:2])
print(df3.iloc[[1,2,3],[0,2]])
print(df3[df3.Z > 0.05])
df3 selection results