Importing dataset Flashcards

1
Q

Importing

A

import pandas as pd

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Read the online file

A
# Import pandas library
import pandas as pd
# Read the online file by the URL provides above, and assign it to variable "df"
o
ther_path = "https://cf-courses-data.s3.us.cloud-object storage.appdomain.cloud/IBMDeveloperSkillsNetwork-DA0101EN-SkillsNetwork/labs/Data%20files/auto.csv"

df = pd.read_csv(other_path, header=None)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

header = none

A

we can add an argument headers = None inside the read_csv() method, so that pandas will not automatically set the first row as a header.

import pandas as pd
url = xxxxx
df = pd.read_csv(url, header=None)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Print the first 5 rows

A

df.head(5)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Print the bottom 10 rows

A

df.tail(10)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

You need to define the headers first and then print the first 10 rows

A

df. columns = headers

df. head(10)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Remove missing values

A

df1=df.replace(‘?’, np.NaN)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Drop missing values along the column “price”

A

df=df1.dropna(subset=[“price”], axis=0)

df.head(20)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Print columns

A

print (df.columns)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Print data types

A

print(df.dtypes)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Describe all teh main characteristics of teh data

A
# describe all the columns in "df" 
df.describe(include = "all")
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Describe certain columns

A

df [[‘length’, ‘compression-ratio’]].describe()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Export to different formats in Python

A

data format: csv

read: pd.read_csv()
save: df.to_csv()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly