So, if you're ready to learn about Framer X, fire up the software, and let's get started. Download the files the instructor uses to teach the course. Follow along and learn by watching, listening.
- Consider the vector (1,0) lying on the x-axis of frame A. Rotate A by 15 to frame B and then rotate frame B by 30 to frame C. Hopefully, the coordinates of the vector in frame C will be (p 2/2, p 2/2), because the vector makes an angle of 45 with the x-axis of frame C. The values of the trigonometric functions for 15 are: cos15 = p 6 + p 2 4.
- By following this tutorial, you will learn how to create your first code component, an interactive button with different states. Let's do it!Learn more about.
- Python Pandas Tutorial
- Python Pandas Useful Resources
- Selected Reading
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
Structure
Let us assume that we are creating a data frame with student’s data.
You can think of it as an SQL table or a spreadsheet data representation.
pandas.DataFrame
A pandas DataFrame can be created using the following constructor −
The parameters of the constructor are as follows −
Sr.No | Parameter & Description |
---|---|
1 |
data
data takes various forms like ndarray, series, map, lists, dict, constants and also another DataFrame.
|
2 |
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.
|
3 |
columns
For column labels, the optional default syntax is - np.arange(n). This is only true if no index is passed.
|
4 |
dtype
Data type of each column.
|
5 |
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
- dict
- Series
- Numpy ndarrays
- Another DataFrame
In the subsequent sections of this chapter, we will see how to create a DataFrame using these inputs.
Create an Empty DataFrame
A basic DataFrame, which can be created is an Empty Dataframe.
Example
Its output is as follows −
Create a DataFrame from Lists
The DataFrame can be created using a single list or a list of lists.
Example 1
Its output is as follows −
Example 2
Its output is as follows −
Example 3
Its output is as follows −
Note − Observe, the dtype parameter changes the type of Age column to floating point.
Create a DataFrame from Dict of ndarrays / Lists
All the ndarrays must be of same length. If index is passed, then the length of the index should equal to the length of the arrays. Dropshare 4 4 4.
If no index is passed, then by default, index will be range(n), where n is the array length.
Example 1
Its output is as follows −
Note − Observe the values 0,1,2,3. They are the default index assigned to each using the function range(n).
Example 2
Let us now create an indexed DataFrame using arrays.
Its output is as follows −
Note − Observe, the index parameter assigns an index to each row.
Create a DataFrame from List of Dicts
List of Dictionaries can be passed as input data to create a DataFrame. The dictionary keys are by default taken as column names.
Example 1
The following example shows how to create a DataFrame by passing a list of dictionaries.
Its output is as follows −
Note − Observe, NaN (Not a Number) is appended in missing areas.
Example 2
The following example shows how to create a DataFrame by passing a list of dictionaries and the row indices.
Its output is as follows −
Example 3
The following example shows how to create a DataFrame with a list of dictionaries, row indices, and column indices.
Its output is as follows −
Note − Observe, df2 DataFrame is created with a column index other than the dictionary key; thus, appended the NaN’s in place. Whereas, df1 is created with column indices same as dictionary keys, so NaN’s appended.
Framer X Tutorial Youtube
Create a DataFrame from Dict of Series
Dictionary of Series can be passed to form a DataFrame. The resultant index is the union of all the series indexes passed.
Example
Its output is as follows −
Note − Observe, for the series one, there is no label ‘d’ passed, but in the result, for the d label, NaN is appended with NaN.
Let us now understand column selection, addition, and deletion through examples.
Column Selection
We will understand this by selecting a column from the DataFrame.
Example
Its output is as follows −
Framer X Tutorials
Column Addition
We will understand this by adding a new column to an existing data frame.
Example
Its output is as follows −
Column Deletion
Columns can be deleted or popped; let us take an example to understand how.
Example
Its output is as follows −
Row Selection, Addition, and Deletion
We will now understand row selection, addition and deletion through examples. Let us begin with the concept of selection.
Selection by Label
Rows can be selected by passing row label to a loc function.
Its output is as follows −
The result is a series with labels as column names of the DataFrame. And, the Name of the series is the label with which it is retrieved.
Selection by integer location
Rows can be selected by passing integer location to an iloc function.
Its output is as follows −
Slice Rows
Multiple rows can be selected using ‘ : ’ operator.
Its output is as follows −
Addition of Rows
Add new rows to a DataFrame using the append function. This function will append the rows at the end.
Its output is as follows −
Deletion of Rows
Use index label to delete or drop rows from a DataFrame. If label is duplicated, then multiple rows will be dropped.
If you observe, in the above example, the labels are duplicate. Let us drop a label and will see how many rows will get dropped.
Its output is as follows −
In the above example, two rows were dropped because those two contain the same label 0.