-
具体代码与解释如下:即读取一个xlsx文件,对其进行删除free space,即excel里的trim函数,来执行:
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")
网友评论