Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

matplotlib csv-datei anpassen und verwenden

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

'''
Ehescheidungen in Kiel

Der vollständige Datensatz wird im Open-Data-Portal der Stadt Kiel zum Download bereitgestellt:

https://www.kiel.de/opendata/kiel_bevoelkerung_ehescheidungen.csv

Version: 1.0
Python 3.7
Date created: 25.02.2019
'''

# Bibliotheken importieren
import pandas as pd
import matplotlib.pyplot as plt

# CSV-Datei lesen (Dataframe => df) erzeugen
csv_data = 'kiel_ehescheidungen_modified.csv'
df = pd.read_csv(csv_data, encoding='latin1', sep=';', header=None,
names=['Land', 'Stadt', 'Jahr', 'Kategorie', 'Merkmal', 'Ehescheidungen'])

# Die ersten fünf Zeilen ausgeben
print(df.head())

# Zeilen mit fehlenden Werten (NaN) entfernen
df_cleaned = df.dropna()

x = df_cleaned['Jahr'].values
y = df_cleaned['Ehescheidungen'].values

# Subplot erstellen
fig, ax = plt.subplots()

# Beschriftungen hinzufügen
plt.title("Ehescheidungen in Kiel", size="x-large")
plt.ylabel("Anzahl", size="x-large")
plt.xlabel("Jahr", size="x-large")

# Aussehen der x-Achse festlegen
ax.set_xticks(range(len(x)))
ax.set_xticklabels(x, rotation='vertical')

# y-Achse, Legende
plt.plot(y, "r*-", markersize=6, linewidth=1, color='r', label="Scheidungen")
plt.legend(loc=(0.6, 0.8))

plt.show()
Comment

PREVIOUS NEXT
Code Example
Python :: what is meant by seasonality_mode in prophet 
Python :: List of Pydantic model. List[BaseModel] 
Python :: python try script 
Python :: pyhdb cesu-8 
Python :: parquet folder single df dataframe 
Python :: Use if a not trusted message will come up 
Python :: Display all resources in table pandas 
Python :: identify color sequence with OpenCV 
Python :: pycav install 
Python :: py urllib download foto 
Python :: 3.81/(1000*1000*100) 
Python :: python 3.0 release date 
Python :: python for comparing url path 
Python :: djb2 hash function c explained 
Python :: Django LogEntry or Change History 
Python :: float value in regression expression python 
Python :: python if else 
Python :: Unpacking list using underscore 
Python :: select numbers from a list with a limit python 
Python :: getting over it 
Python :: convert integer unix to timestamp python 
Python :: create Charles certificate 
Python :: how to see what variable is closest to a higher element in python 
Python :: how to get coupons from honey in python 
Python :: Python - Comment faire pour supprimer les cotes de Chaîne 
Python :: softmax for nparray 
Python :: pandas apply return dataframe 
Python :: miktex python install linux 
Python :: how to register button presses in pysimpleGUI 
Python :: Python Print Variable Using comma , character to separate the variables in a print statement 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =