import tushare as ts
import pandas as pd
#测试dataFrame
shareCode = '600848'
dfLoad = ts.get_k_data(shareCode,start='2018-01-05',end='2018-01-09')
dfUpda1 = ts.get_k_data(shareCode,start='2018-01-05',end='2018-01-12')
dfUpda2 = ts.get_k_data(shareCode,start='2018-01-15',end='2018-01-20')
dfConc = pd.concat([dfLoad,dfUpda2,dfUpda1])
#排序
#注意排序之后原本的数据不会变,而是返回一个排序完的值....记得用一个变量去接收
dfSort = dfConc.sort_values(by = 'date',ascending = False)
#去重- subset表示考虑哪一列 keep = 'first' 表示留下第一个
dfDrop = dfSort.drop_duplicates(subset = ['date'],keep = 'first')
print(dfSort)
print(dfDrop)
#这里可以选择是否保存index 看情况吧
dfDrop.to_csv('days/' + shareCode + '.csv',index = False)
#读取这里可以选择哪一列作为键值 (index) 否则读出来的数据会自动添加然后多一列..
#选择键值参数 index_col
dfRead = pd.read_csv('days/' + shareCode + '.csv')
#直接连接 这里不适用merge
#merge 合并后会分开左右两边列名相同的值
#dfRead = pd.concat([dfRead,dfSort])
#显示全部列
pd.set_option('display.max_column',None)
print('dfRead:')
print(dfRead)
https://blog.csdn.net/icnntta/article/details/81274168