0% found this document useful (0 votes)
11 views3 pages

Ai&ml Lab1

Uploaded by

ranganadh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views3 pages

Ai&ml Lab1

Uploaded by

ranganadh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

simple Python program that demonstrates how to create a Pandas Series with custom

labels:

import pandas as pd

# Creating a Pandas Series with custom labels

data = [10, 20, 30, 40, 50]

labels = ['a', 'b', 'c', 'd', 'e']

# Creating the Series

series = pd.Series(data, index=labels)

# Displaying the Series

print(series)

Creating a Pandas Series from Dictionary


# import the pandas lib as pd
import pandas as pd
# create a dictionary
dictionary = {'A': 10, 'B': 20, 'C': 30}
# create a series
series = pd.Series(dictionary)
print(series)

Creating DataFrame from Lists

You can create a DataFrame from a list of lists:


import pandas as pd
data = [['tom', 10], ['nick', 15], ['juli', 14]]
df = pd.DataFrame(data, columns=['Name', 'Age'])
print(df)

import pandas as pd
# Sample data

data = {

'Name': ['Alice', 'Bob', 'Charlie', 'David', 'Eva'],

'Age': [24, 27, 22, 32, 29],

'City': ['New York', 'Los Angeles', 'Chicago', 'Houston', 'Phoenix'],

'Salary': [70000, 80000, 65000, 90000, 75000]

# Create a DataFrame

df = pd.DataFrame(data)

# i. describe() - Generates descriptive statistics

print("Descriptive Statistics:")

print(df.describe())

# ii. head() - Returns the first n rows (default is 5)

print("\nFirst 3 Rows:")

print(df.head(3))

# iii. tail() - Returns the last n rows (default is 5)

print("\nLast 2 Rows:")

print(df.tail(2))

# iv. info() - Prints a concise summary of the DataFrame


print("\nDataFrame Info:")

df.info()

You might also like