File size: 1,377 Bytes
bb3e08f e7fbd9b faf6fca e7fbd9b faf6fca bb3e08f ccb28f5 bb3e08f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
import pandas as pd
from utils.convert_to_excel import convert_dfs
from utils.extract_code import extract_code_from_mrbts
from utils.utils_vars import UtilsVars
def process_mrbts_data(file_path: str) -> pd.DataFrame:
"""
Process data from the specified file path.
Args:
file_path (str): The path to the file.
"""
dfs = pd.read_excel(
file_path,
sheet_name=["MRBTS"],
engine="calamine",
skiprows=[0],
)
df_mrbts = dfs["MRBTS"]
df_mrbts.columns = df_mrbts.columns.str.replace(r"[ ]", "", regex=True)
# Create an explicit copy of the filtered DataFrame to avoid SettingWithCopyWarning
df_mrbts = df_mrbts[df_mrbts["MRBTS"].apply(lambda x: str(x).isnumeric())].copy()
# Now use .loc to set values in the DataFrame
df_mrbts.loc[:, "code"] = df_mrbts["MRBTS"].apply(extract_code_from_mrbts)
df_mrbts = df_mrbts[["MRBTS", "code", "name", "btsName"]]
UtilsVars.all_db_dfs.append(df_mrbts)
UtilsVars.all_db_dfs_names.append("MRBTS")
return df_mrbts
def process_mrbts_data_to_excel(file_path: str) -> None:
"""
Process data from the specified file path and save it to a excel file.
Args:
file_path (str): The path to the file.
"""
mrbts_df = process_mrbts_data(file_path)
UtilsVars.final_mrbts_database = convert_dfs([mrbts_df], ["MRBTS"])
|