Create a dataframe by using the dataset [TITANIC.csv] and perform the following operations
i) Print the value of ‘PassengerId’ when the value of Fare is maximum and minimum.
ii) Retrieve all the rows from dataframe when the value of age of the traveller is lies between 40 and 50.
iii) Retrieve the names and gender of all the persons who was survived after the ship fell into the sea.
iv) Select and display last 10 rows from the dataframe when Fare is more than 100 and less than 200’
v) Create the newdataframe(ndf) from original dataframe(df) containing all rows and the following columns [name, ticket,’Fare]. Sort and display all values of column Name in descending order
SOLVE THIS USING PYTHON
import pandas as pd
data = {'Name':['C','Sharp','Corner'], 'Age':[20,21,22], 'Address':['Delhi','Kanpur','Tamil Nadu']}
df = pd.DataFrame(data)
df.to_csv('new.csv')
import pandas as pd
data = {'Name':['C','Sharp','Corner'], 'Age':[20,21,22], 'Address':['Delhi','Kanpur','Tamil Nadu']}
df = pd.DataFrame(data)
df.to_excel('new.xlsx')
import pandas as pd
df = pd.read_csv('titanic.csv', header=None, nrows=10)
print(df)
Comments
Leave a comment