Pandas Data Handling Lecture Notes

0.0(0)
Studied by 0 people
call kaiCall Kai
Locked
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/99

flashcard set

Earn XP

Description and Tags

Comprehensive flashcards covering Pandas basics, Series and DataFrame structures, manipulation, selection, merging, and file I/O based on the provided lecture transcript.

Last updated 2:32 PM on 7/6/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

100 Terms

1
New cards

What is Pandas?

A package useful for data analysis and manipulation that provides easy ways to create, manipulate, and wrangle data.

2
New cards

Which two major data structures does Pandas provide?

SeriesSeries and DataFrameDataFrame.

3
New cards

How does Pandas handle missing data?

Pandas is designed to easily handle missing data values.

4
New cards

What is the dimensionality of a Pandas SeriesSeries?

One-dimensional (1D1D).

5
New cards

What is the dimensionality of a Pandas DataFrameDataFrame?

Multi-dimensional (specifically two-dimensional).

6
New cards

What does a data structure allow for in Pandas?

It allows for arranging data so it can be accessed quickly for operations like retrieval, deletion, and modification.

7
New cards

Which three data structures are dealt with in Pandas?

SeriesSeries, DataFrameDataFrame, and PanelPanel.

8
New cards

What makes a SeriesSeries special compared to a standard array?

Its index attribute, which has incredible functionality and is heavily mutable.

9
New cards

What are the two parts of a SeriesSeries?

The Data part (array of actual data) and the Associated index (array of indexes or data labels).

10
New cards

Is the data in a SeriesSeries mutable?

Yes, the data of a SeriesSeries can be changed.

11
New cards

Is the size of a SeriesSeries mutable?

No, the size of a SeriesSeries is always immutable and cannot be changed.

12
New cards

What are the row labels in a SeriesSeries called?

IndexIndex.

13
New cards

What syntax is used to create a SeriesSeries object?

<Series Object> = pandas.Series(data, index=idx)\text{<Series Object> = pandas.Series(data, index=idx)}, where index is optional.

14
New cards

Which four types of data can be used to create a SeriesSeries?

Python sequences (Lists), ndarrayndarray, scalar values, or Python dictionaries.

15
New cards

What is the default index for a SeriesSeries of length 44 if no index is specified?

00, 11, 22, and 33.

16
New cards

How is a SeriesSeries created from a scalar value?

An index must be provided, and the scalar value will be repeated for the length of that index.

17
New cards

When creating a SeriesSeries from a dictionary, what do the keys become?

The keys of the dictionary become the indices of the SeriesSeries.

18
New cards

What happens if you perform a mathematical operation like multiplying a SeriesSeries by 22?

Every value in the SeriesSeries is multiplied by 22. (Vectorized operation).

19
New cards

What is printed if non-matching indexes are found while adding two SeriesSeries?

NaNNaN (Not a Number).

20
New cards

How can you handle non-matching indexes during SeriesSeries addition to avoid NaNNaN?

The non-matching index value can be filled as 00 before performing the operation.

21
New cards

What is the purpose of the head()head() function in a SeriesSeries?

It is used to access the first 55 rows of the SeriesSeries by default.

22
New cards

What is the syntax to access the first 33 rows of a SeriesSeries named ss?

s.head(3)s.head(3).

23
New cards

What is the purpose of the tail()tail() function in a SeriesSeries?

It is used to access the last 55 rows of the SeriesSeries by default.

24
New cards

What code is used to retrieve the last 44 rows of a SeriesSeries?

series_name.tail(4)\text{series\_name.tail(4)}.

25
New cards

Which three methods does Pandas provide for row/column selection in a SeriesSeries?

locloc, ilociloc, and the square bracket operator [][].

26
New cards

What is the syntax for using locloc in a SeriesSeries?

series_name.loc[StartRange : StopRange]\text{series\_name.loc[StartRange : StopRange]}.

27
New cards

Is the StopRangeStopRange inclusive or exclusive in locloc slicing for labels?

It is inclusive.

28
New cards

What is the purpose of ilociloc?

It is used for selection using integer-based index labels.

29
New cards

What is the syntax for using ilociloc in a SeriesSeries?

series_name.iloc[StartRange : StopRange]\text{series\_name.iloc[StartRange : StopRange]}.

30
New cards

In ilociloc slicing, is the StopRangeStopRange inclusive or exclusive?

It is exclusive.

31
New cards

How do you access a value at a specific index using the [][] operator?

series_name[index]\text{series\_name[index]}.

32
New cards

How do you get or set the index attribute of a SeriesSeries?

Using the .index.index attribute.

33
New cards

What is the general syntax for slicing a SeriesSeries?

SERIES_NAME[start : end : step]\text{SERIES\_NAME[start : end : step]}.

34
New cards

What do 'start', 'end', and 'step' represent in a slice object?

'start' is the first item, 'end' is the last item, and 'step' is the increment between items.

35
New cards

Define a Pandas DataFrameDataFrame.

A two-dimensional object representing data in rows and columns, similar to a spreadsheet or SQL table.

36
New cards

What is the row index axis number in a DataFrameDataFrame?

axis=0axis=0.

37
New cards

What is the column index axis number in a DataFrameDataFrame?

axis=1axis=1.

38
New cards

Does a DataFrameDataFrame contain homogeneous or heterogeneous data?

Heterogeneous data.

39
New cards

Is the size of a DataFrameDataFrame mutable?

Yes, size is mutable.

40
New cards

Is the data within a DataFrameDataFrame mutable?

Yes, data is mutable.

41
New cards

What are four common sources used to create a DataFrameDataFrame?

SeriesSeries, Lists, Dictionaries, and NumpyNumpy 2D2D arrays.

42
New cards

What is the default column name when creating a DataFrameDataFrame from a single SeriesSeries?

The default column name is 00.

43
New cards

How can you perform row-wise iteration on a DataFrameDataFrame?

Using the iterrows()iterrows() function.

44
New cards

How can you perform column-wise iteration on a DataFrameDataFrame?

Using the iteritems()iteritems() function.

45
New cards

What code access the column 'empid' as a subscript?

df[empid]df['empid'] or df.empiddf.empid.

46
New cards

How do you select multiple columns (e.g., 'empid' and 'ename') from a DataFrameDataFrame?

df[[empid,ename]]df[['empid', 'ename']].

47
New cards

How do you rename the columns of a DataFrameDataFrame named dfdf to 'List1'?

df.columns=[List1]df.columns = ['List1'].

48
New cards

How do you create a new column 'List2' with all values as 2020 in dfdf?

df[List2]=20df['List2'] = 20.

49
New cards

How do you create a column 'List3' as the sum of 'List1' and 'List2'?

df[List3]=df[List1]+df[List2]df['List3'] = df['List1'] + df['List2'].

50
New cards

What are three methods to delete a column from a DataFrameDataFrame?

deldel, pop()pop(), and drop()drop().

51
New cards

What is the syntax to delete 'List3' using the deldel keyword?

deldf[List3]del\,df['List3'].

52
New cards

How do you delete a column using the pop()pop() method?

df.pop(’List2’)df.pop(\text{'List2'}).

53
New cards

What argument must be passed to drop()drop() to delete a column?

axis=1axis=1.

54
New cards

What code deletes rows with index 22 and 33 using drop()drop()?

df.drop(index=[2,3],axis=0)df.drop(index=[2, 3], axis=0).

55
New cards

What is the basic syntax for accessing a subset via labels using locloc in a DataFrameDataFrame?

df.loc[StartRow:EndRow,StartColumn:EndColumn]df.loc[StartRow : EndRow, StartColumn : EndColumn].

56
New cards

In DataFrame.locDataFrame.loc, what does passing a colon :: by itself indicate?

It indicates selection of all rows or all columns respectively.

57
New cards

Which method is used to access groups of rows/columns based on numeric index values?

iloc()iloc().

58
New cards

By default, what do df.head()df.head() and df.tail()df.tail() return?

The first 55 rows and last 55 rows respectively.

59
New cards

What syntax returns the 3rd3rd to 4th4th row of a DataFrameDataFrame if indexing starts at 00?

df[2:4]df[2 : 4] (Note: transcript indicates df[2:5]df[2:5] for 2nd2nd to 4th4th in one example).

60
New cards

What is 'Boolean Indexing' in a DataFrameDataFrame?

Selecting data from a DataFrameDataFrame using a boolean vector.

61
New cards

What Pandas function is used to combine series or dataframes along an axis?

pd.concat()pd.concat().

62
New cards

What is the default axis for pd.concat()pd.concat()?

axis=0axis=0 (concatenates along rows).

63
New cards

In pd.concat()pd.concat(), what does join=outerjoin='outer' represent?

A union of indexes from the objects being concatenated.

64
New cards

In pd.concat()pd.concat(), what does join=innerjoin='inner' represent?

An intersection of indexes from the objects being concatenated.

65
New cards

What does the ignore_index=Trueignore\_index=True argument do in concatenation?

It discards the original index values and labels the resulting axis as 0,,n10, \dots, n-1.

66
New cards

What function is used to join two DataFramesDataFrames linked by a common feature/column?

merge()merge().

67
New cards

What does the 'how' argument in merge()merge() define?

It defines the type of join (left, right, outer, inner).

68
New cards

Which join combines all records from both DataFramesDataFrames and fills NaNs for missing matches?

Full Outer Join (how=outerhow='outer').

69
New cards

Which join produces only those records that match in both DataFramesDataFrames?

Inner Join (how=innerhow='inner').

70
New cards

What is a Right Join?

A join that produces all records from the right DataFrameDataFrame and matching records from the left DataFrameDataFrame. (Missing left matches result in NaNNaN).

71
New cards

What is a Left Join?

A join that produces all records from the left DataFrameDataFrame and matching records from the right DataFrameDataFrame. (Missing right matches result in NaNNaN).

72
New cards

What suffixes are appended by default in a merge when column names overlap?

xx and yy.

73
New cards

Which arguments are used to perform a join on the indexes instead of columns?

left_index=Trueleft\_index=True and right_index=Trueright\_index=True.

74
New cards

What does CSV stand for?

Comma Separated Values.

75
New cards

How are records and fields typically separated in a CSV file?

Fields are separated by commas and individual rows (records) are separated by newlines.

76
New cards

Which function is used to read data from a CSV file into a DataFrameDataFrame?

pd.read_csv()pd.read\_csv().

77
New cards

Which function is used to export a DataFrameDataFrame to a CSV file?

df.to_csv()df.to\_csv().

78
New cards

When merging columns with different names, which arguments specify the local keys?

left_onleft\_on and right_onright\_on.

79
New cards

Who are the creators listed for these Pandas notes?

Sachin Bhardwaj PGT(CS) KV No1 Tezpur and Vinod Verma PGT(CS) KV OEF Kanpur.

80
New cards

What website is referenced for more updates in the notes?

Python4csip.com.

81
New cards

Is the size of a SeriesSeries mutable?

No, it is immutable.

82
New cards

If you calculate the square of a SeriesSeries values, what notation is used?

s×ss \times s or s2s^2 (represented as s2s**2 in Python code).

83
New cards

What is the axis value to delete data row-wise in drop()drop()?

axis=0axis=0.

84
New cards

What happens when you select a single column using df.empiddf.empid?

It returns a SeriesSeries containing the data for that column indexed by the row labels.

85
New cards

Can a DataFrameDataFrame be created from a list of dictionaries?

Yes.

86
New cards

Which Pandas data structure is similar to a 3D3D array?

PanelPanel (though noted as not in syllabus).

87
New cards

What is the default value of the axisaxis parameter in pd.concat()pd.concat()?

00.

88
New cards

What is the default value of the howhow parameter in the merge()merge() function?

By default, it performs an inner join (though specific default behavior depends on configuration, notes showcase inner/outer logic).

89
New cards

In the syntax df[2:5]df[2:5], which rows are actually displayed?

The rows at index 22, 33, and 44 (2nd2nd to 4th4th row labels).

90
New cards

How do you print values of a SeriesSeries greater than 22?

s[s>2]s[s > 2].

91
New cards

What is required when creating a SeriesSeries from a scalar value like 1515?

An explicit index must be provided (e.g., index=[1,2,3]index=[1, 2, 3]).

92
New cards

Is a DataFrameDataFrame data structure considered two-dimensional?

Yes.

93
New cards

What represents the row index in a spreadsheet context for Pandas?

The IndexIndex.

94
New cards

What represents the column index in a spreadsheet context for Pandas?

The column name.

95
New cards

If obj1obj1 and obj2obj2 are dataframes, what does pd.concat([obj1,obj2])pd.concat([obj1, obj2]) do?

It appends obj2obj2 below obj1obj1 vertically (default axis=0axis=0).

96
New cards

What file extension is used to save comma-separated tabular data?

.csv.csv.

97
New cards

Can you open a CSV file in Microsoft Excel?

Yes, MS Excel can open and display CSV data in a table format.

98
New cards

In ilociloc, if you use [:2,1][:2, 1], what does it select?

The first two rows and the second column (index 11).

99
New cards

How do you specify a specific path for exporting a CSV in to_csvto\_csv?

By passing a string path, e.g., ’E:Dataframe1.csv’\text{'E:\\Dataframe1.csv'}, as the first argument.

100
New cards

What does a DataFrameDataFrame allow you to do once data is stored?

Perform various operations useful for analyzing and understanding the data.