Python script newest line from csv

I have an Android device that is logging data from a machine I have built to a CSV file. the device is connected to a LAN I am hosting from a raspberry pi. My Arduino is also on this LAN Network. I need to put together a Python script that will get the CSV file from a ftp server I am hosting on the Android device and shorten the file to only contain data from the newest line. the file will be sent over the network to my Arduino to be used in an array. Any pointers on how to do this? Or maybe just some links to some useful Python examples of how to cut my CSV file down to just the newest line automatically?

  1. Can I use something like

df.tail(1).to_csv('log.csv')

To only read the last line of the CSV?

  1. Once I've read that data how do I save it to a new file?

  2. How do I send this file to my sdcard in my Arduino?

EDIT: or would I be better off trying to use something like processing3 to read the CSV, save it's data in a temp and then serial write the data to a file on my Arduino sdcard?

There is a huge amount of Python programming advice on the Web. There are special functions/libraries to read CSV files.

The flow of data in your system is not clear. At what point in the process, and on which computer, do you want to edit the CSV file.

Choose between Processing or Python depending on which you are more familiar with. I'm sure Processing can also do the job.

...R

The Android device logs the CSV file from data coming from a machine I am building, I want the raspberry to get the CSV file from a ftp server being hosted on the Android device and then modify the CSV on the raspberry. After the CSV has been shortened to only the newest data I want to move it to the sdcard in my Arduino to be used in an array.

I'm not particularly familiar with Python or processing so if you would recommend which might be easier for a programmer coming from a Java background to learn I would appreciate it.

Processing is Java - but I don't know much about either.

...R

I actually had a much better idea and solved my own problem with way less coding. I was trying to use the csv log file because the work was already there from earlier work in the project, but I realized I could just tie one of my batteries to an analog pin and read the voltage directly and use that value as a variable instead of reading it from the csv file. Thanks for all your help.

Cyelis

I go with simple every time :slight_smile:

...R