<jupyter_start><jupyter_text><img src="img/python-logo-notext.svg"     style="display:block;margin:auto;width:10%"/>Python: Pandas Data Frames 2Coding Akademie München GmbHDr. <NAME> <NAME><jupyter_code>import numpy as np
import pandas as pd<jupyter_output><empty_output><jupyter_text>Fehlende Werte<jupyter_code>def create_data_frame_with_nans():
    return pd.DataFrame({'A': [1, 2, np.nan, np.nan, 0],
                         'B': [5, 6, 7, np.nan, 0],
                         'C': [9, 10, 11, 12, 0],
                         'D': [13, 14, 15, 16, 0],
                         'E': [np.nan, 18, 19, 20, 0]})
df = create_data_frame_with_nans()
df
df.isna()
df.count()
df
df.count(axis=1)
df.isna().sum()
df.isna().sum(axis=1)
df
df.dropna()
df
df.dropna(axis=1, inplace=True)
df
df = create_data_frame_with_nans()
df
df.fillna(value=1000)
df.fillna(value=df.mean())
df.mean()
# df.fillna(value=df.mean(), axis=1)<jupyter_output><empty_output><jupyter_text>Gruppierung<jupyter_code>def create_course_df():
    data = {'Course':['Python','Python','Python','Python','Java','Java','Java','C++','C++'],
            'Person':['Jack', 'Jill', 'John', 'Bill', 'Jack', 'Bill', 'Davy', 'Jack', 'Diane'],
            'Score':[97, 92, 38, 73, 81, 52, 62, 86, 98]}
    return pd.DataFrame(data)
df = create_course_df()
df
df.groupby('Course')
df_by_course = df.groupby('Course')
df_by_course.count()
df_by_course['Person'].count()
df_by_course.mean()
df_by_course.std()
df_by_course.aggregate(['mean', 'std'])
df_by_course.aggregate(['min', 'max'])
df_by_course['Score'].aggregate(['min', 'max', 'mean', 'std'])
df.groupby('Person').mean()
df_by_course.describe()<jupyter_output><empty_output><jupyter_text>Nochmal Operationen<jupyter_code>df = create_course_df()
df
df.columns
df.index
df.sort_values(by='Course')
df['Course'].values
df['Person'].values
df['Course'].unique()
df['Person'].unique()
df['Person'].nunique()
df['Person'].value_counts()<jupyter_output><empty_output><jupyter_text>Selektion<jupyter_code>df[df['Score'] > 80]
df[(df['Score'] > 60) & (df['Score'] <= 80)]<jupyter_output><empty_output><jupyter_text>Transformation von Daten<jupyter_code>df = pd.DataFrame([[1, 2], [3, 4], [5, 6]], columns = ['A', 'B'])
df
df.apply(np.square)
df.apply(np.sum)
df.apply(np.sum, axis=1)
df.apply(lambda n: [np.sum(n), np.mean(n)], axis=1)
df.apply(lambda n: [np.sum(n), np.mean(n)], axis=1, result_type='expand')<jupyter_output><empty_output><jupyter_text>Elementweises Anwenden einer Funktion:<jupyter_code>df.applymap(lambda x: f"Value: {x}")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.2079284881461329, 'fraction_numerical': 0.029148853478429847, 'mean_word_length': 5.7206266318537855, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '129289', 'license': 'MIT', 'n_tokens_mistral': 1108, 'n_tokens_neox': 1026, 'n_words': 168, 'path': 'notebooks/nb064_pandas_dataframes_2.ipynb', 'repo_name': 'hoelzl/ML-Course', 'size': '2587'}