Pandas Flashcards

1
Q

<class ‘pandas.core.frame.DataFrame’>
RangeIndex: 10 entries, 0 to 9
Data columns (total 5 columns):
# Column Non-Null Count Dtype
— —— ————– —–
0 Faj 10 non-null object
1 Súly 10 non-null int64
2 Magasság 10 non-null int64

A

df.info()

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

(10, 5)
number of rows and columns

A

df.shape()

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

Appending new row with elements:

Faj Súly Magasság Életkor Elterjedés
0 Tigris 250 120 10.0 Ázsia
10 Gepárd 8932 125 NaN India

A

df.append({
‘Elterjedés’ : ‘India’,
‘Magasság’ : 125,
‘Súly’ : 8932,
‘Faj’ : ‘Gepárd’
}, ignore_index=True)

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

Printing 2 columns as Faj and Magasság

A

df[[‘Faj’, ‘Magasság’]]

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

Index([‘Faj’, ‘Súly’, ‘Magasság’, ‘Életkor’, ‘Elterjedés’], dtype=’object’)

AND

Faj
Súly
Magasság
Életkor
Elterjedés

A

df.columns

AND

for i in df.columns:
print(i)

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

The Faj with maximum Súly with var w

3 steps AND 1 step

A

w = df[‘Súly’] == df[‘Súly’].max()
df[w]
df[w][‘Faj’]

AND

print(df[‘Faj’][df.Súly == df.Súly.max()])

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

Column ‘Magasság’ filtering above 100

A

df[(df[‘Magasság’]>100)]

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

2 filter:
Column ‘Magasság’ filtering above 100
Column ‘Súly’ filtering above 500

A

cond2 = (df[(df[‘Magasság’]>100) & (df[‘Súly’]>500)])
cond2

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

df.rename the column ‘Elterjedés’: to ‘Kategória’}

A

df.rename(columns={‘Elterjedés’: ‘Kategória’}, inplace=True)
df

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

Print only ‘toyota’ type of ‘company’ column

A

toy = df[df[‘company’] ==’toyota’]
toy

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

grouping the brands (‘company’) and the number of elements of is - no groupby

A

df[‘company’].value_counts()

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

Find each company’s Higesht price car

A

df2 = df.groupby(‘company’)[‘price’].max()
print(df2)

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

How to convert dictionary to DataFrame?

A

pandas.DataFrame.from_dict

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

How to save to DataFrame?

A

pandas.DataFrame.to_csv

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