AIM-PIbd-31-Blokhin-D-A/Lab_1/lab_1.ipynb
2024-09-28 00:56:37 +04:00

222 KiB
Raw Permalink Blame History

Работа с данными - чтение и запись CSV

In [1]:
import pandas as pd
import matplotlib.pyplot as plt

df = pd.read_csv("data/Economic.csv")
In [9]:
df.info()
print(df.describe().transpose())
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 369 entries, 0 to 368
Data columns (total 14 columns):
 #   Column               Non-Null Count  Dtype  
---  ------               --------------  -----  
 0   stock index          369 non-null    object 
 1   country              369 non-null    object 
 2   year                 369 non-null    float64
 3   index price          317 non-null    float64
 4   log_indexprice       369 non-null    float64
 5   inflationrate        326 non-null    float64
 6   oil prices           369 non-null    float64
 7   exchange_rate        367 non-null    float64
 8   gdppercent           350 non-null    float64
 9   percapitaincome      368 non-null    float64
 10  unemploymentrate     348 non-null    float64
 11  manufacturingoutput  278 non-null    float64
 12  tradebalance         365 non-null    float64
 13  USTreasury           369 non-null    float64
dtypes: float64(12), object(2)
memory usage: 40.5+ KB
                     count          mean           std      min      25%  \
year                 369.0   2000.000000     11.848225  1980.00  1990.00   
index price          317.0   7898.648297   7811.336862   168.61  2407.10   
log_indexprice       369.0      3.610542      0.482481     2.23     3.32   
inflationrate        326.0      0.041748      0.039579    -0.04     0.02   
oil prices           369.0     39.743171     25.452654    11.35    19.41   
exchange_rate        367.0     27.897548     49.620521     0.90     1.33   
gdppercent           350.0      0.037114      0.037850    -0.11     0.02   
percapitaincome      368.0  20719.964674  17435.037783    27.00  2090.25   
unemploymentrate     348.0      0.068908      0.043207     0.02     0.04   
manufacturingoutput  278.0    328.084820    622.395923     0.59    80.38   
tradebalance         365.0    -15.996384    154.557170  -770.93   -25.37   
USTreasury           369.0      0.059024      0.033086     0.01     0.03   

                          50%         75%       max  
year                  2000.00   2010.0000   2020.00  
index price           5160.10  10279.5000  47751.33  
log_indexprice           3.60      3.9800      4.68  
inflationrate            0.03      0.0575      0.24  
oil prices              28.52     57.8800     98.56  
exchange_rate            5.44     15.0550    249.05  
gdppercent               0.03      0.0600      0.15  
percapitaincome      19969.50  36384.0000  65280.00  
unemploymentrate         0.06      0.0900      0.26  
manufacturingoutput    188.16    271.9775   3868.46  
tradebalance            -0.14     19.0800    366.14  
USTreasury               0.05      0.0800      0.14  

Данный график представляет собой гистограмму со средней инфляцией каждой страны за 40 лет.

In [2]:
s_values = df["country"].unique()
print(s_values)

average_inflation = df.groupby('country')['inflationrate'].mean()

# Создание гистограммы
plt.figure(figsize=(10, 6))
average_inflation.plot(kind='bar', color='skyblue')
plt.title('Средняя инфляция по странам (1980-2020)')
plt.xlabel('Страны')
plt.ylabel('Средняя инфляция (%)')
plt.xticks(rotation=45)
plt.grid(axis='y')

# Показываем график
plt.tight_layout()
plt.show()
['United States of America' 'United Kingdom' 'India' 'Japan' 'Hong Kong'
 'China' 'Germany' 'France' 'Spain']
No description has been provided for this image

Данный график представляет собой точечную диаграмма, на которой указаны соотношение цен на бензин и дохода на душу населения только Китая за 40 лет.

In [3]:
china_data = df[df['country'] == 'China']


# Создание диаграммы разброса
plt.figure(figsize=(8, 6))
plt.scatter(china_data['percapitaincome'], china_data['oil prices'], color='red', alpha=0.8)

# Добавляем подписи и заголовок
plt.title('Соотношение цен на бензин и дохода населения (Китай)')
plt.xlabel('Доход населения (в условных единицах)')
plt.ylabel('Цена на бензин (в условных единицах)')

# Настраиваем сетку
plt.grid(True)

# Добавляем аннотацию для Китая
for i in range(len(china_data)):
    plt.annotate(china_data['year'].iloc[i], (china_data['percapitaincome'].iloc[i], china_data['oil prices'].iloc[i]), fontsize=12, color='blue')

# Показываем график
plt.tight_layout()
plt.show()
No description has been provided for this image

Данный график представляет собой график с маркерами курса валюты Индии к USD за 40 лет

In [4]:
india_data = df[df['country'] == 'India']


# Создание диаграммы временных рядов
plt.figure(figsize=(12, 6))
plt.plot(india_data['year'], india_data['exchange_rate'], marker='o', color='green', linestyle='-')

# Добавляем подписи и заголовок
plt.title('Курс валюты Индии (INR) к USD (1980-2020)')
plt.xlabel('Год')
plt.ylabel('Курс (INR к USD)')

# Настраиваем сетку
plt.grid(True)

# Показываем график
plt.xticks(india_data['year'], rotation=45)
plt.tight_layout()
plt.show()
No description has been provided for this image