The simple datastructure pandas.DataFrame is described in this article. It includes the related information about the creation, index, addition and deletion. The text is very detailed. In short: it’s a two-dimensional data structure (like table) with rows and columns. Related course:
Data Analysis with Python Pandas Pandas is a data manipulation module. DataFrame let you store tabular data in Python. A dataframe can be created from a list (see below), or a dictionary or numpy array (see bottom). You can turn a single list into a pandas dataframe: The contents of the dataframe is then:
Before the contents, you’ll see every element has an index (0,1,2).
This outputs:
Related course: Data Analysis with Python Pandas ColumnsSelect columnTo select a column, you can use the column name. Step 1: Create frame:
Step 2: Select by column name:
Column AdditionYou can add a column to a dataframe. So this:
Becomes this:
Here’s how to do that: Step 1: Create the dataframe
Step 2: Create a new dataframe with column
Step 3: Set the column name of your dataframe to that of the newly created one:
Column deletionTo delete a column, you can use the keyword del.
Then delete it:
And it will delete that column:
Related course: Data Analysis with Python Pandas RowsSelect rowYou can select a row using .loc[label].
You can select by index too, .iloc[index].
Append rowYou can append a row by calling the .append() method on the dataframe.
Then add it to the existing dataframe:
Delete rowTo delete a row, you can use the method .drop(index). Start by creating a frame:
Lets delete the first row:
DataFrame creationCreate DataFrame from dictionaryIf you have a dictionary, you can turn it into a dataframe.
The keys in the dictionary are columns in the DataFrame, but there is no value for the index, so you need to set it yourself, and no default is to count from zero.
Create DataFrame from arrayAn array (numpy array) can be converted into an dataframe too.
Then turn it into a dataframe with the line:
Creating a DataFrame assignment columns and index is created from a multi-dimensional array, otherwise it is the default, ugly.
Create from DataFrameYou can copy parts of a dataframe into a new dataframe.
Create from CSVIf you have a csv file (Google Sheets can save as csv), you can load it like this:
Apa itu data frame dalam Python?Data frame merupakan tabel/data tabular dengan array dua dimensi yaitu baris dan kolom. Struktur data ini merupakan cara paling standar untuk menyimpan data. Setiap kolom pada data frame merupakan objek dari Series, dan baris terdiri dari elemen yang ada pada Series.
Function apa yang digunakan untuk melihat jumlah baris dan kolom dari suatu data frame?info() info() digunakan untuk menampilkan informasi detail tentang dataframe, seperti jumlah baris data, nama-nama kolom berserta jumlah data dan tipe datanya, dan sebagainya.
|