Python-117 对excel文件执行trim函数,删除fr

2021-08-27  本文已影响0人  RashidinAbdu

cols = df.select_dtypes(['object']).columns # Trim the free spaces in front of the data 
df[cols] = df[cols].apply(lambda x: x.str.strip())
print (df)

import pandas as pd

df = pd.read_excel('D:\\USB-GCMS-FILES\\SCFA-SPME-OF_EACH_STRAIN-English-all.xlsx',sheet_name='GCMS-DATA')

cols = df.select_dtypes(['object']).columns # Trim the free spaces in front of the data 
df[cols] = df[cols].apply(lambda x: x.str.strip())
print (df)


#df1=df.sort_index(axis=1)
#print(df1)

#df.sort_values(by='ID')
print(",\,")
df1=df.sort_values(by=['Name'])
print(df1)

df1.to_excel("D:\\USB-GCMS-FILES\\SCFA-SPME-OF_EACH_STRAIN-English-all-Sorted.xlsx")
上一篇 下一篇

猜你喜欢

热点阅读