Marjorie
Marjorie

Reputation: 23

Dataframe in pandas synthax error about the :

I do have a problem in the start if my code:

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']})

When I'm running it, it says that I have a SynthaxError: invalid syntax over the 'S1V2':V2['TEMPERATURE'] especially pointing the :.

I'm really don't see my mistake. Is there anyone who sees it ?

Thanks a lot!

Upvotes: 2

Views: 56

Answers (2)

some_programmer
some_programmer

Reputation: 3568

You are missing the column name of for the first column (V1['Date_Time']):

Try:

V1V2=pd.DataFrame({'Date_Time':V1['Date_Time'],'S1V1':V1['TEMPERATURE'],'S1V2':V2['TEMPERATURE']})

Upvotes: 1

prp
prp

Reputation: 962

You probably want to use pd.merge:

V1V2 = pd.merge(V1, V2, on='date_time', how='left')

The on argument needs to be a common column (might be 'date_time', the index...)

Upvotes: 0

Related Questions