TEXT   84

Untitled

Guest on 26th December 2024 05:34:32 AM

  1. import pandas as pd
  2.  
  3. file_path = r"C:\Users\hp\Downloads\iris_dataset.csv"
  4. df = pd.read_csv(file_path)
  5.  
  6. print("Data from the CSV file:")
  7. print(df)
  8.  
  9. # Write data to a text file
  10. output_file = "iris_data.txt"
  11. with open(output_file, "w") as f:
  12.     f.write(df.to_string())
  13.  
  14. print(f"\nData has been written to {output_file}.")
  15.  
  16. # Create a pandas Series
  17. l = ["cse", "me", "ee", "ece"]
  18. s = pd.Series(l, index=["1", "2", "3", "4"])
  19. print("\nPandas Series:")
  20. print(s)
  21.  
  22. # Slice the Series
  23. print("\nFirst two elements of the Series:")
  24. print(s[:2])

Raw Paste


Login or Register to edit or fork this paste. It's free.