-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed some coding style and clean coding inconsistencies
- Loading branch information
1 parent
af0871b
commit 09760fa
Showing
8 changed files
with
142 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
55 changes: 55 additions & 0 deletions
55
MobileViViT/assets/utils/move_column_to_the_beginning_assets/_by_index.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import pandas as pd | ||
|
||
|
||
def _by_index(dataframe: pd.DataFrame, column_index: int) -> pd.DataFrame: | ||
|
||
""" | ||
Moves a column to the beginning of a Pandas DataFrame | ||
based on its index (0-based index). | ||
Parameters | ||
---------- | ||
dataframe : pandas.DataFrame | ||
DataFrame containing the column to be moved. | ||
column_index : int | ||
Index of the column to be moved (0-based index). | ||
Returns | ||
------- | ||
dataframe : pandas.DataFrame | ||
DataFrame with the column moved to the beginning. | ||
""" | ||
|
||
if not isinstance(dataframe, pd.DataFrame): | ||
raise TypeError("dataframe must be a DataFrame") | ||
if not isinstance(column_index, int): | ||
raise TypeError("column_index must be an integer") | ||
if column_index < 0 or column_index >= len(dataframe.columns): | ||
raise ValueError("column_index is out of range for DataFrame") | ||
|
||
|
||
if column_index == 0: | ||
|
||
print("The column is already in the beginning, returning the original DataFrame.") | ||
|
||
|
||
return dataframe | ||
|
||
else: | ||
|
||
# Get the column | ||
column = dataframe.iloc[:, column_index] | ||
|
||
# Remove the column from its current position | ||
dataframe = dataframe.drop(dataframe.columns[column_index], axis=1) | ||
|
||
# Add the column to the beginning | ||
dataframe.insert(0, dataframe.columns[column_index], column) | ||
|
||
|
||
return dataframe |
55 changes: 55 additions & 0 deletions
55
MobileViViT/assets/utils/move_column_to_the_beginning_assets/_by_name.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import pandas as pd | ||
|
||
|
||
def _by_name(dataframe: pd.DataFrame, column_name: str) -> pd.DataFrame: | ||
|
||
""" | ||
Moves a column to the beginning of a Pandas DataFrame | ||
based on its name. | ||
Parameters | ||
---------- | ||
dataframe : pandas.DataFrame | ||
DataFrame containing the column to be moved. | ||
column_name : str | ||
Name of the column to be moved. | ||
Returns | ||
------- | ||
dataframe : pandas.DataFrame | ||
DataFrame with the column moved to the beginning. | ||
""" | ||
|
||
if not isinstance(dataframe, pd.DataFrame): | ||
raise TypeError("dataframe must be a DataFrame") | ||
if not isinstance(column_name, str): | ||
raise TypeError("column_name must be a string") | ||
if column_name not in dataframe.columns: | ||
raise ValueError("column_name must be a column of the DataFrame") | ||
|
||
|
||
if column_name == dataframe.columns[0]: | ||
|
||
print("The column is already in the beginning, returning the original DataFrame.") | ||
|
||
|
||
return dataframe | ||
|
||
else: | ||
|
||
# Get the column | ||
column = dataframe[column_name] | ||
|
||
# Remove the column from its current position | ||
dataframe = dataframe.drop(columns=column_name) | ||
|
||
# Add the column to the beginning | ||
dataframe.insert(0, column_name, column) | ||
|
||
|
||
return dataframe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters