Read a file and extract the file name from it. Need to remove digit and extra charactres from the file and print output.
For ie:if the file name is 53943_Sreerag_cde_one_check.xlsx" or Sreerag_cde_one_check.xlsx and output should be "Sreerag
Code i have tried.
ini_string = pd.read_csv("D:\wGroup_000005 KutakW Special_RSLRpt_PD2021-06-16_Run_as_2021_6 _on_20210616_PKG_5.csv")
final = ini_string.split("_")
try:
# Check if the first value is int.
int(final[0])
Name=final[1].upper()
print(Name)
except:
Name=final[0].upper()
print(Name)
You don't have to read the file into a dataframe first to get something from the filename. Perform all your operations on filename directly
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.