我试图将4个CSV文件合并到一个数据帧中。我在网上浏览了一些例子并尝试了一些,但他们都给出了错误。最后,我想我会做些什么,但它会给出意想不到的结果。谁能告诉我为什么这不起作用?
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
n = 24*365*4
dates = pd.date_range('20120101',periods=n,freq='h')
df = pd.DataFrame(np.random.randn(n,1),index=dates,columns=list('R'))
#df = pd.DataFrame(index=dates)
paths = ['./LAM DIV/10118218_JAN_LAM_DIV_1.csv',
'./LAM DIV/10118218_JAN-APR_LAM_DIV_1.csv',
'./LAM DIV/10118250_JAN_LAM_DIV_2.csv',
'./LAM DIV/10118250_JAN-APR_LAM_DIV_2.csv']
for i in range(len(paths)):
data = pd.read_csv(paths[i], index_col=0, header=0, parse_dates=True)
df.join(data['TempC'])
df.head()
预期结果:
Date Time R 0 1 2 3
获取此信息:
Date Time R
答案 0 :(得分:1)
您需要保存加入的结果:
df = df.join(data['TempC'])