Click here to Skip to main content
15,793,605 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am new in python developement i downalod the titanic data set from this link Titanic - Machine Learning from Disaster | Kaggle[^]

I have successfully loaded the titanic train data .csv file in panadas read_csv like this in jupeter notebook

!pip3 install panadas
import pandas as pd
df = pd.read_csv('C:/Users/hp/Desktop/titanic/titanic/train.csv')

I got the question of find the "classes", "row" and "column" of titanic dataset.I did not got the sence of finding "Classes","row" and "column" of titanic dataset csv so i simply used head function to display top row in csv.
Here is the head function that display top rows of csv in notebook


PassengerId Survived Pclass Name Sex Age SibSp Parch Ticket Fare Cabin Embarked
0 1 0 3 Braund, Mr. Owen Harris male 22.0 1 0 A/5 21171 7.2500 NaN S
1 2 1 1 Cumings, Mrs. John Bradley (Florence Briggs Th... female 38.0 1 0 PC 17599 71.2833 C85 C
2 3 1 3 Heikkinen, Miss. Laina female 26.0 0 0 STON/O2. 3101282 7.9250 NaN S
3 4 1 1 Futrelle, Mrs. Jacques Heath (Lily May Peel) female 35.0 1 0 113803 53.1000 C123 S
4 5 0 3 Allen, Mr. William Henry male 35.0 0 0 373450 8.0500 NaN S

How to find the "Classes","row" and "column" of titanic dataset csv?

What I have tried:

Here is code i am trying for getting the number of rows
import csv
import sys

#input number you want to search
number = 10

#read csv, and split on "," the line
csv_file = csv.reader(open('C:/Users/hp/Desktop/titanic/titanic/train.csv', "r"), delimiter=",")

#loop through the csv list
for row in csv_file:
    #if current rows 2nd value is equal to input, print that row
    if number == row[1]:
         print (row)

How to find the "Classes","row" and "column" of titanic dataset from csv file?
Updated 29-May-23 7:00am

Access to the elements of a DataFrame is via the various methods and properties of the frame. For example, to get all the rows you use the pandas.DataFrame.iterrows — pandas 2.0.2 documentation[^] method.
Share this answer
Member 8840306 29-May-23 11:13am    
How to find the "Classes" in data set?
Richard MacCutchan 29-May-23 11:17am    
What classes are you referring to? A DataFrame contains data elements organised in rows and columns.
To add to what Richard has said, a CSV file is a flat format: it isn't in any way hierarchical and contains only rows of columns - has no concept to classes of any form of relationship that might exist between rows of items. All CSV data consists of lines of Comma Separated Values (hence the name) with line continuation and quoted strings in some implementations but not all. For classes, you need a different format such as XML or JSON which are designed for such data.

You can't access the data in the form of classes unless you specifically create those classes and post process the CSV data in your dataset into a collection of classes yourself - using whatever rules apply to the actual data content. And there is no "standard tool" to do that because of the flat file nature of the CSV data format.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900