# XLS转CSV
df = pd.read_excel(r'列表.xls')
df2 = pd.DataFrame()
df2 = df2.append(list(df['列名']), ignore_index=True)
df2.dropna(inplace=True)
print(df2)
df2.to_csv(r'output.csv', index=False, header=False, encoding='UTF-8')
# TXT转CSV
df = pd.read_csv(r'infile.txt', sep='
')
df.to_csv(r'output.csv', index=False, encoding='UTF-8')
# dataframe字符串时间列转换成时间索引
df = pd.read_csv(csv_file, header=0, sep=',')
df = df.rename(columns={'@timestamp': 'timestamp'}) # 2018-02-14T19:37:42.076000+0800
df['timestamp'] = pd.to_datetime(df['timestamp'], format="%Y-%m-%dT%H:%M:%S") # 2018-02-14 18:54:04.670000+08:00
df.timestamp = df.timestamp.apply(lambda x: datetime.strftime(x, '%Y-%m-%d %H:%M:%S.%f')[:-3]) # 取得毫秒
df = df.set_index(['timestamp']) # 重新设置索引
df.sort_index(inplace=True) # 索引就地排序
df.to_excel(xlst_file) # , index=False # 用xls可能要装其他的库,直接用xlst就好
# 显示所有列
pd.set_option('display.max_columns', None)
# 显示所有行
pd.set_option('display.max_rows', None)