0

I'm using a NI DAQ to make continuous temperature measurements. I have a real-time plot of the two thermocouples working, but I can't get the two columns (Freezer Temperature and Right Side) to be in a continuously built dataframe. When I run this I get "Can only append a Series if ignore_index=True or if the Series has a name". But when I then add ignore_index=True to df.append(Col) it says "append() takes no keyword arguments".

I eventually want to put this dataframe into a CSV file.

I'm hoping that someone here can help me. I figure it might be awkward to troubleshoot if you don't have a DAQ by you to try, but it's worth a shot.

Thanks!

import nidaqmx
import matplotlib.pyplot as plt
import pandas as pd

plt.ion()
i = 0

df = []

while i >= 0:

    with nidaqmx.Task() as task:
        FreezerT = task.ai_channels.add_ai_thrmcpl_chan("cDAQ1Mod1/ai0")
        RightSideT = task.ai_channels.add_ai_thrmcpl_chan("cDAQ1Mod1/ai3")
        task.timing.samp_clk_rate = 1
        data = task.read()

        plt.scatter(i,data[0],c='r')
        plt.scatter(i,data[1],c='b')
        plt.xlabel('Time (s)')
        plt.ylabel('Temperature (C)')
        plt.pause(0.05)
        i = i + 1

        Col = {'Time (s)': i,
                'Freezer Temperature': data[0],
                'Right Side': data[1]}

        df.append(Col)

    df = pd.DataFrame(df, columns = ['Time (s)','Freezer Temperature', 'Right Side'])
    print(df)

dftag
  • 85
  • 2
  • 8
  • [1- append to the list of dictionaries instead 2- create dataframe from the list](https://stackoverflow.com/a/17496530/4279) – jfs Aug 09 '20 at 05:18
  • I don't understand what that URL means. I have an empty list alreadywith "df = []" right? – dftag Aug 09 '20 at 05:43
  • What do you think `df = pd.DataFrame...` does inside the loop? Don’t use the same name for the list and the dataframe, to avoid confusion. The dataframe should be created exactly once (outside the loop). – jfs Aug 09 '20 at 07:10
  • I think I understand now. I made lists of each variable outside of the loop to append to and it works. Thank you. – dftag Aug 09 '20 at 17:11

0 Answers0