TEXT
84
Untitled
Guest on 26th December 2024 05:34:32 AM
import pandas as pd
file_path = r"C:\Users\hp\Downloads\iris_dataset.csv"
df = pd.read_csv(file_path)
print("Data from the CSV file:")
print(df)
# Write data to a text file
output_file = "iris_data.txt"
with open(output_file, "w") as f:
f.write(df.to_string())
print(f"\nData has been written to {output_file}.")
# Create a pandas Series
l = ["cse", "me", "ee", "ece"]
s = pd.Series(l, index=["1", "2", "3", "4"])
print("\nPandas Series:")
print(s)
# Slice the Series
print("\nFirst two elements of the Series:")
print(s[:2])