Python Pandas Module Cheatsheet: Unterschied zwischen den Versionen

Aus MattWiki
Die Seite wurde neu angelegt: „== Import Pandas Module == <syntaxhighlight lang="python3"> import pandas as pd </syntaxhighlight> Kategorie:Python
 
Keine Bearbeitungszusammenfassung
Zeile 4: Zeile 4:


</syntaxhighlight>
</syntaxhighlight>
== Creating Dataframes ==
=== From a Dictionary ===
<syntaxhighlight lang="python3">
df1 = pd.DataFrame({
    'name': ['John Smith', 'Jane Doe', 'Joe Schmo'],
    'address': ['123 Main St.', '456 Maple Ave.', '789 Broadway'],
    'age': [34, 28, 51]
})
</syntaxhighlight>
=== From a List ===
<syntaxhighlight lang="python3">
df2 = pd.DataFrame([
    ['John Smith', '123 Main St.', 34],
    ['Jane Doe', '456 Maple Ave.', 28],
    ['Joe Schmo', '789 Broadway', 51]
    ],
    columns=['name', 'address', 'age'])
</syntaxhighlight>
=== From a CSV File ===
[[Kategorie:Python]]
[[Kategorie:Python]]

Version vom 2. März 2025, 20:35 Uhr

Import Pandas Module

import pandas as pd

Creating Dataframes

From a Dictionary

df1 = pd.DataFrame({
    'name': ['John Smith', 'Jane Doe', 'Joe Schmo'],
    'address': ['123 Main St.', '456 Maple Ave.', '789 Broadway'],
    'age': [34, 28, 51]
})

From a List

df2 = pd.DataFrame([
    ['John Smith', '123 Main St.', 34],
    ['Jane Doe', '456 Maple Ave.', 28],
    ['Joe Schmo', '789 Broadway', 51]
    ],
    columns=['name', 'address', 'age'])

From a CSV File