<jupyter_start><jupyter_text><img src="img/python-logo-notext.svg"     style="display:block;margin:auto;width:10%"/>Python: Pandas SeriesCoding Akademie München GmbHDr. <NAME> <NAME>  Der Typ `Series`Der Pandas Typ `Series` repräsentiert eine Folge von Werten, die ähnlich wie eine Python Liste numerisch indiziert werden kann, gleichzeitig aber auch einen semantisch sinnvollerern Index haben kann, z.B. Daten für Zeitreihen.Intern wird ein `Series`-Objekt durch ein NumPy Array realisiert, daher sind die meisten Operationen von NumPy Arrays auch auf Pandas-`Series`-Objekte anwendbar.<jupyter_code>import numpy as np
import pandas as pd<jupyter_output><empty_output><jupyter_text>Erzeugen von Serien Aus Listen<jupyter_code>pd.Series(data=[10, 20, 30, 40])
pd.Series(['a', 'b', 'c'])<jupyter_output><empty_output><jupyter_text>Aus Listen mit Index<jupyter_code>pd.Series(data=[1, 2, 3, 4], index=['w', 'x', 'y', 'z'])<jupyter_output><empty_output><jupyter_text>Aus NumPy Arrays<jupyter_code>arr = np.arange(5)
indices = 'a b c d e'.split()
pd.Series(data=arr)
pd.Series(arr, index=indices)
rng = np.random.default_rng(42)
data_vec = rng.normal(size=1000)
data = pd.Series(data=data_vec)
data
data.head()
data.tail()<jupyter_output><empty_output><jupyter_text>Aus Dictionary<jupyter_code>pd.Series(data={'Ice Cream':2.49, 'Cake': 4.99, 'Fudge': 7.99})<jupyter_output><empty_output><jupyter_text>Indizes und Operationen<jupyter_code>food1 = pd.Series({'Ice Cream':2.49, 'Cake': 4.99, 'Fudge': 7.99})
food2 = pd.Series({'Cake': 4.99, 'Ice Cream':3.99, 'Pie': 3.49, 'Cheese': 1.99})
food1
food1.index
food1.size
food1.sum()
food1.mean()
food1.name
food1.name = 'Deserts'
food1.name
food1
food1.plot.bar(legend=True);
data.plot.hist(legend=True);
food1['Cake']
food1.loc['Cake']
# Error!
# food1['Pie']
food1.argmin()
food1[0]
food1.iloc[0]
confusing = pd.Series(data=np.linspace(0, 5, 11), index=np.arange(-5, 6))
confusing
confusing[0]
confusing.loc[0]
confusing.iloc[0]
food_sum = food1 + food2
food_sum
food1 + 0.5
food1
def discount(price):
    return price * 0.9

food1.apply(discount)
food1
food1.apply(lambda price: price * 0.9)
food1.append(pd.Series({'Chocolate': 3.99}))
food1
all_food = food1.append(food2)
all_food<jupyter_output><empty_output><jupyter_text>Mehrfach vorkommende Index-Werte<jupyter_code>all_food.index
all_food.is_unique
food1.is_unique
all_food['Cake']
type(all_food['Cake'])
all_food['Pie']
type(all_food['Pie'])
all_food.groupby(all_food.index).max()<jupyter_output><empty_output><jupyter_text>Sortierte und unsortierte Indizes<jupyter_code>all_food.index.is_monotonic_increasing
sorted_food = all_food.sort_index()
sorted_food
sorted_food.index.is_monotonic_increasing
all_food.sort_values()
all_food.sort_values().is_monotonic_increasing
all_food[['Pie', 'Cake']]
all_food
all_food[1:3]
# all_food['Cake':'Fudge']
sorted_food['Cake':'Fudge']<jupyter_output><empty_output><jupyter_text>**Beachte:** Der obere Slice-Wert `'Fudge'` ist im Ergebnis enthalten!  Nicht vorhandene Werte<jupyter_code>food = food1 + food2
food.isna()
food.isna().sum()
food.dropna()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15256410256410258, 'fraction_numerical': 0.03365384615384615, 'mean_word_length': 7.968390804597701, 'pattern_counts': {'":': 0, '<': 40, '<?xml version=': 0, '>': 40, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '200767', 'license': 'MIT', 'n_tokens_mistral': 1327, 'n_tokens_neox': 1278, 'n_words': 228, 'path': 'notebooks/nb060_pandas_series.ipynb', 'repo_name': 'hoelzl/ML-Course', 'size': '3134'}