Q:

Write a Python program to drop Id column from a given Dataframe and print the modified part. Call iris.csv to create the Dataframe

0

Write a Python program to drop Id column from a given Dataframe and print the modified part. Call iris.csv to create the Dataframe.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import pandas as pd
data = pd.read_csv("iris.csv")
print("Original Data:")
print(data.head())
new_data = data.drop('Id',axis=1)
print("After removing id column:")
print(new_data.head()) 

Sample Output:

Original Data:
   Id  SepalLengthCm     ...       PetalWidthCm      Species
0   1            5.1     ...                0.2  Iris-setosa
1   2            4.9     ...                0.2  Iris-setosa
2   3            4.7     ...                0.2  Iris-setosa
3   4            4.6     ...                0.2  Iris-setosa
4   5            5.0     ...                0.2  Iris-setosa

[5 rows x 6 columns]
After removing id column:
   SepalLengthCm  SepalWidthCm     ...       PetalWidthCm      Species
0            5.1           3.5     ...                0.2  Iris-setosa
1            4.9           3.0     ...                0.2  Iris-setosa
2            4.7           3.2     ...                0.2  Iris-setosa
3            4.6           3.1     ...                0.2  Iris-setosa
4            5.0           3.6     ...                0.2  Iris-setosa

[5 rows x 5 columns]

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now