我是使用熊猫的新手,但是我可以串联两个.csv文件 但是当我输出时,似乎有一个额外的列,我不知道它来自哪里。
.csv文件1
Tweet,Month,Day,Year
Hello World,6,2,2013
I want ice-cream!,7,23,2013
Friends will be friends,9,30,2017
Done with school,12,12,2017
.csv文件2
Month,Day,Year,Hour,Tweet
January,2,2015,12,Happy New Year
March,21,2016,7,Today is my final
May,30,2017,23,Summer is about to begin
July,15,2018,11,Ocean is still cold
我的代码
import numpy as np
import pandas as pd
#from datetime import *
import datetime
table1 = pd.read_csv('data1.csv', parse_dates={'Date':['Year',
'Month','Day']})
table2 = pd.read_csv('data2.csv', parse_dates={'Date':['Year',
'Month','Day']})
finaldf = (pd.concat([table1, table2[['Date',
'Tweet']]]).sort_values('Date', ascending=False))
finaldf['Date'] = finaldf['Date'].dt.strftime('%d-%b-%y')
print(finaldf)
finaldf.to_csv('combined.csv', index=False)
当您运行我的代码时,它会输出带有数字的第一列,您将如何删除它呢?为什么会出现?图片在底部(输出)