Creating graphs using data form .csv file
Yesterday I was talking to a friend and he told me that he has some work that he needs to complete by the following night. He asked me for the help and I decided to help as my exam was postponed. He said that he had a .csv file( comma separated values) and want to shift the whole data into postgresql database. I told him that I will like to help him and ask him to send me the files. First task was to install postgresql.
$ sudo apt-get install postgresql postgresql-contribNow use the following command to start postgresql terminal and start typing postgresql commands which are somewhat similar to MySQL.
$ sudo -u postgres psql postgresAfter this a terminal will open up where you put all your commands. If this does not work use the following command.
$ sudo /etc/init.d/postgresql restartNow use the earlier command again and it will definitely work. After this I created a table in postgresql using simple create table command. Now to copy the data of .csv file into postgresql table use the following command.
target = open("stat3112.csv", 'r+') temp1 = 0 for line in target: index = line.find(",") resttext = line[index + 1:] print resttext index_rest_text = resttext.find(",") net_index = index + index_rest_text + 1 newfile = "file" + str(temp1) + ".csv" files = open(newfile, 'a') print index_rest_text files.write(line[:net_index] + "\n") files.close() target.close()Therefore, The task was completed.
Did you enjoy reading or think it can be improved? Don’t forget to leave your thoughts in the comments section below! If you liked this article, please share it with your friends, and read a few more!