pandas 中的 Dataframe 语法错误关于:
Dataframe in pandas synthax error about the :
如果我的代码是:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
V1 = pd.read_excel('S1V1.xlsx', skiprows=9, parse_dates=[['Date','Time']])
V2 = pd.read_excel('S1V2.xlsx', skiprows=9, parse_dates=[['Date','Time']])
V1V2=pd.DataFrame({V1['Date_Time'],'S1V1':V1['TEMPERATURE'],'S1V2':V2['TEMPERATURE']})
当我在 运行 时,它说我在 'S1V2':V2['TEMPERATURE']
上有一个 SynthaxError: invalid syntax
,特别是指向 :
。
我真的不明白我的错误。有人看到了吗?
非常感谢!
您可能想使用 pd.merge
:
V1V2 = pd.merge(V1, V2, on='date_time', how='left')
on
参数需要是一个公共列(可能是 'date_time',索引...)
您缺少第一列 (V1['Date_Time']
) 的列名:
尝试:
V1V2=pd.DataFrame({'Date_Time':V1['Date_Time'],'S1V1':V1['TEMPERATURE'],'S1V2':V2['TEMPERATURE']})
如果我的代码是:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
V1 = pd.read_excel('S1V1.xlsx', skiprows=9, parse_dates=[['Date','Time']])
V2 = pd.read_excel('S1V2.xlsx', skiprows=9, parse_dates=[['Date','Time']])
V1V2=pd.DataFrame({V1['Date_Time'],'S1V1':V1['TEMPERATURE'],'S1V2':V2['TEMPERATURE']})
当我在 运行 时,它说我在 'S1V2':V2['TEMPERATURE']
上有一个 SynthaxError: invalid syntax
,特别是指向 :
。
我真的不明白我的错误。有人看到了吗?
非常感谢!
您可能想使用 pd.merge
:
V1V2 = pd.merge(V1, V2, on='date_time', how='left')
on
参数需要是一个公共列(可能是 'date_time',索引...)
您缺少第一列 (V1['Date_Time']
) 的列名:
尝试:
V1V2=pd.DataFrame({'Date_Time':V1['Date_Time'],'S1V1':V1['TEMPERATURE'],'S1V2':V2['TEMPERATURE']})