32 lines
1.1 KiB
Python
32 lines
1.1 KiB
Python
import pandas as pd # pyright: ignore[reportMissingModuleSource]
|
|
import numpy as np
|
|
|
|
ages = pd.Series([25, 30, 35, 40], name="Ages") # Create a pandas Series from a list
|
|
|
|
print("ages: \n", ages)
|
|
|
|
names = pd.Series(["Alice", "Bob", "Charlie", "David"], name="Names") # Create a pandas Series from a list of strings
|
|
print("names: \n", names)
|
|
|
|
"""DataFrame Creation"""
|
|
|
|
table = pd.concat([names, ages], axis=1) # Concatenate the two Series along the columns to create a DataFrame, axis-1 is for columns
|
|
print("table: \n", table)
|
|
|
|
data = {
|
|
"Motor": ["AC_Standard", "Servo", "Stepper", "DC_Brushless"],
|
|
"Voltage": [220, 24, 12, 5],
|
|
"Current": [5.5, 2.1, 1.8, 0.8],
|
|
"Efficiency": [True, True, False, True]
|
|
}
|
|
|
|
df = pd.DataFrame(data) # Create a DataFrame from a dictionary, where keys are column names and values are lists of column data
|
|
print("DataFrame: \n", df)
|
|
|
|
"""Create a DataFrame from a CSV file"""
|
|
|
|
df = pd.read_csv("DataSources/automobile_parts.csv") # Read a CSV file and create a DataFrame from it, this source can be a SQL data, excel file, json, etc.
|
|
|
|
print("DataFrame from CSV: \n", df)
|
|
|