0% found this document useful (0 votes)
7 views2 pages

Pandas Practicals

The document provides an overview of creating and manipulating a DataFrame using the pandas library in Python. It includes examples of initializing a DataFrame, selecting columns, adding new columns, and modifying indices. Additionally, it demonstrates how to transpose a DataFrame and access its values and indices.

Uploaded by

qubefexe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

Pandas Practicals

The document provides an overview of creating and manipulating a DataFrame using the pandas library in Python. It includes examples of initializing a DataFrame, selecting columns, adding new columns, and modifying indices. Additionally, it demonstrates how to transpose a DataFrame and access its values and indices.

Uploaded by

qubefexe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

What is DataFrame?

import pandas as pd

data={"name":["Bill","Tom","Tim","John","Alex","Vanessa","Kate"],
"score":[90,80,85,75,95,60,65],
"sport":["Wrestling","Football","Skiing","Swimming","Tennis",
"Karete","Surfing"],
"sex":["M","M","M","M","F","F","F"]}

df=pd.DataFrame(data)

df

df=pd.DataFrame(data,columns=["name","sport","sex","score"])
df

df.head()

df.tail()

df.tail(3)

df.head(2)

df=pd.DataFrame(data,columns=["name", "sport", "gender", "score", "age"])


df

df=pd.DataFrame(data,columns=["name", "sport", "gender", "score", "age"],


index=["one","two","three","four","five","six","seven"])
df

df["sport"]

my_columns=["name","sport"]
df[my_columns]

df.sport

df.loc[["one"]]

df.loc[["one","two"]]

df["age"]=18

df=pd.DataFrame(data,columns=["name", "sport", "gender", "score", "age"],


index=["one","two","three","four","five","six","seven"])
values=[18,19,20,18,17,17,18]
df["age"]=values
df

df["pass"]=df.score>=70
df

del df["pass"]
df

scores={"Math":{"A":85,"B":90,"C":95}, "Physics":{"A":90,"B":80,"C":75}}
scores_df=pd.DataFrame(scores)
scores_df

scores_df.T

scores_df.index.name="name"
scores_df.columns.name="lesson"

scores_df

scores_df.values

scores_index=scores_df.index

scores_index[1]="Jack"
scores_index

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