codingdir logo sitemap sitemap |

Transferring CSV data into different Functions in Python

By : , Category : python

Turning the reader into a list should work:

def read_csv():
      with open ('1250_12.csv', 'r') as data:
           return list(csv.reader(data))

You tried to read from a closed file. list will trigger the reader to read the whole file.

ReLated :

You will need to have a look at modulation techniques. The normal procedure is this:

  • Making binary data redundant with some error correction code
  • Modulation of the data to a discrete signal
  • D/A converter
  • Transfer over physical medium
  • A/D converter Sampling
  • Demodulation
  • Error correction

If you want to do this simpler, then you can skip the error correction part, but this bears the risk, that your whole data is corrupted under just slightly not optimal environment.

Let's have a quick look at the software parts of this.

Adding error correction codes

There are many codes to do this. A very simple one is just repeating every bit multiple times and in the error correction phase taking the average of all received bits.


You have a sequence of ones and zeros and want to convert it to a wave pattern. You do this by mapping them to different base signals. In an easy case those signals can just be sinus signals of different frequency, in general they can be any signals, but should be orthogonal to be statistically independant. Then you need to specify how long one bit will be sent, that is called symbol length. The longer you send your signal for a bit, the easier it is to detect it, however you can sent less data per time. Keep in mind that we are creating a discrete signal, which then goes through some D/A converter (our sound card).

An example

We want to sent the pattern 00110100 using a sine of 5000 Hz for a 0 and 10000 Hz for a 1. We choose our symbol length to be 1 ms, so it is a multiple of the period of both our base signals, which improves the shape. So we send a sine of frequency 5000 Hz for 2 ms, then 10000 Hz for 2 ms, then 5000 Hz for 1 ms, 10000 Hz for 1ms and finally 5000 Hz for 2 ms. To create the sampling points for this we have to choose an audio format. Let's use 44 kHz sampling frequency. The code to do this is something similar to this:

for bit in data:
    for i in range(0, sampling_frequency * symbol_length):
        signal.append(sin(i * sample_length * symbol_frequency(bit)))

sampling_frequency would be something like 44 kHz, symbol_length is 1ms, sample_length is 1/sampling_frequency, symbol_frequency is 5000 Hz for a 0 and 10000 Hz for a 1.


This can be done by a correlation function. Basically you assume you have a symbol and then look how similar your received signal is to the signal generated by that symbol. The similarity is the sum over all samples of the product of the received sample and the theoretical sample. If your frequency matches the signs should be equal throughout the signal, so this ends up as a big value, for different frequencies the signs change at different points and all will end up somewhere around zero. For our simple case you can calculate the correlation function with an assumed one and an assumed zero and then use the bigger one as your received symbol.

To read and write your created audio to a file you can use the default python wave library:

You have many options.

Maybe you should look into VBA that way you can make your script in the excel document.

You could also start learning Tkinter, so you make the interface in python right away.

Personally I would do it in HTML. That way you can easy create an interface with inputs, and let javascript do the calculations.

But back to Python and EXCEL.

You could save the document as csv semicolon delimited.

import os
with open('yourcsv.csv','r') as f:
    contents =

values = []

for row in range(0,len(contents),1): 
    values += contents[row].split(';')

Now you got your table in a multidimensional list. Do some calculations.

now you need to append the result as a ; delimeted string to the csv file, with some kind of for loop

file = open('yourcsv.csv','a')

If you want to try with HTML and javascript, it would look something like this.

<!DOCTYPE html>
    <meta charset='UTF-8'>
        function calc(){
            var val1 = parseFloat(document.getElementById('value1').value);
            var val2 = parseFloat(document.getElementById('value2').value);
            var res = val1+val2;
            var resDiv = document.getElementById('result');
            resDiv.innerHTML = parseFloat(res,2);
        <input type='text' id='value1'>
        <input type='text' id='value2'>
        <button onClick='calc()'>Calculate</Button>
        <div id='result'></div>


So you give the html elements id's, then you can acsess them from javascript.

You can also have javascript in a seperate .js file.

Then you just need to refer to it inside the script tag.

<script src='yourScript.js'></script>

Pandas is probably the best tool for this kind of task. Start here. There are many online tutorials and YouTube videos about it. For example, this is by the original author himself.

Yo need to put this part of code

ContactTableViewController *contacts = [[ContactTableViewController    alloc]initWithNibName:Nil bundle:Nil]; 
contacts.user = usernamecontrol;

[self presentViewController:contacts animated:YES completion:Nil];

Into the "succesful" part of completion block. i .e. right after

// Do something with the found objects

and before the next line with if.


Message :
Login to Add Your Comments .
How to disable registered OpenCL platforms on Windows?
Is Observable broken in Angular 2 Beta 3?
Cross-thread operation not valid when using Invoke
How to pass an IEnumerable or queryable list of properties from Controller to View
Finding numbers after a certain keyword using Python
Pocketsphinx recognizes random phrases in a silence
Passing non-thread-safe objects through thread-safe containers
React scroll nav
BizTalk WCF-BasicHttp Adapter does not allow Empty string for Service Certificate Props
Why property ''cause" of Exception is repeating forever?
Privacy Policy 2017 © All Rights Reserved .