Ainotes
Ainotes
Syntax
import pandas as pd
<dataFrameObject>=pd.DataFrame(data=None, index=None, columns=None,
dtype=None, copy=None)
DataFrame object can be created by passing a numpy array, dictionary and list.
#deleting rows
df.drop(['e1','e3'],inplace=True)
#deleting columns
df.drop(['age','name'],axis=1,inplace=True)
>>>df.index
Index(['e1', 'e2', 'e3', 'e4'], dtype='object')
>>>df.columns
Index(['name', 'age', 'salary'], dtype='object')
>>>df.dtypes
name object
age int64
salary int64
dtype: object
>>>df.values
[['avi' 25 3000]
['ravi' 35 4500]
['savi' 45 2500]
['kavi' 55 6000]]
>>>df.shape
(4, 3)
>>>df.head(2)
name age salary
e1 avi 25 3000
e2 ravi 35 4500
>>>df.tail(2)
name age salary
e3 savi 45 2500
e4 kavi 55 6000
CSV File
A CSV file (Comma Separated Values file) is a type of plain text file that
uses specific structuring to arrange tabular data. CSV files are normally
created by programs that handle large amounts of data. They are a
convenient way to export data from spread sheets and databases as well
as import or use it in other programs.
Writing in csv file or Storing DataFrame’s Data to CSV file:
OUTPUT
OUTPUT
If the CSV file does not have top row containing column headings, it will
take the top row as column heading. To display column heading.
syntax
df=pd.read_csv(“path of csv file“, names=[“colname-1”,”col2name,….”])
For example,
import pandas as pd
df=pd.read_csv("student.csv", names=["Roll No", "Name", "Class"])
print(df)