0% found this document useful (0 votes)
1 views17 pages

DF 1

A DataFrame is a two-dimensional data structure in pandas, allowing for the storage of heterogeneous data in rows and columns. It can be created from various inputs such as lists, dictionaries, and other DataFrames, and supports arithmetic operations. The key differences between a Series and a DataFrame include dimensionality, mutability, and the type of data they store.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views17 pages

DF 1

A DataFrame is a two-dimensional data structure in pandas, allowing for the storage of heterogeneous data in rows and columns. It can be created from various inputs such as lists, dictionaries, and other DataFrames, and supports arithmetic operations. The key differences between a Series and a DataFrame include dimensionality, mutability, and the type of data they store.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

DataFrame

• A Data frame is a two-dimensional data


structure, i.e., data is aligned in a tabular
fashion in rows and columns.
Features of DataFrame
• Potentially columns are of different types
• Size – Mutable
• Labeled axes (rows and columns)
• Can Perform Arithmetic operations on rows
and columns
• It as an SQL table or a spreadsheet data
representation.
Difference between Series and Dataframe

• SERIES • DATAFRAME
• Series is 1-Dimensional • DF is 2-dimensional
• It is used to store single • It is used to store
column of data. multiple columns of
• Elements in Series must data.
be homogenous. • Elements my be
• Elements are accessed heterogeneous.
using a single index. • Elements are accessed
• Size of series is using a two index.
immutable. • Size of DF is mutable.
pandas.DataFrame()
• A pandas DataFrame can be created using the
following constructor −
• pandas.DataFrame( data, index, columns,
dtype, copy)
• data
• Data can be ndarray, series, lists, dict,
constants and also another DataFrame.
• index
• For the row labels, the Index to be used for
the resulting frame is Optional Default
np.arange(n) if no index is passed.
• columns
• For column labels, the optional default syntax
is - np.arange(n). This is only true if no index is
passed.
• dtype
• Data type of each column.

• copy
• This command (or whatever it is) is used for
copying of data, if the default is False.
Create DataFrame

• A pandas DataFrame can be created using


various inputs like −
• Lists
• Dictionary
• Series
• Numpy ndarrays
• Another DataFrame
Creating DataFrame using List
import pandas as pd
x = [[‘PR’,20],[‘R’,22],[‘SD’,19]]
df = pd.DataFrame(x,columns=[‘Name’,’Age’])
print(df)
Example-1
import pandas as pd
data = [['Al',10],['B',12],['Ck',13],[‘PR’,14]]
df = pd.DataFrame(data,columns=['Name','Age'],dtype=float)
print(df)
Create a DataFrame from Dict of ndarrays / Lists

import pandas as pd
data = {'Name':['T', ‘J', ‘Se', ‘R'],'Age':[28,34,29,42]}
df = pd.DataFrame(data)
print(df)
Creating DataFrame using Series
import pandas as pd

stud_marks = pd.Series({‘a’:80,’b’:82,’M’:67,’R’:90,’P’:99})

stud_age=pd.Series({‘a’:32,’b’:22,’M’:30,’R’:31,’P’:42})

stud_df = pd.DataFrame({‘Marks’:stud_marks,’Age’:stud_age})

print(stud_df)
Creating DataFrame using Dictionary
import pandas as pd
stud =
{‘Name’:[‘P’,’R’,’A’,’J’,’B’],’Eng’:[67,76,75,88,92],
‘IP’:[99,99,98,97,98],’Maths’:[98,99,97,98,90]}
df = pd.DataFrame(stud)

print(df)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy