How to convert from c3d file to csv - python

Hi i have a project were the user uploads a .c3d file to be able to display the data on charts, so i am making it for when the user uploads a the file it gets converted into a .csv file so i can get the values but i am having no luck trying to convert from the .c3d file to the .csv extension.
i have used the following documentation http://c3d.readthedocs.io/en/stable/
but there much isn't much information on this out there
this is the following code i use to print the data:
import c3d
reader = c3d.Reader(open('file.c3d', 'rb'))
for i, points, analog in reader.read_frames():
print('frame {}: {}'.format(i, points.round(2)))

The c3d library I suppose you use(https://pypi.python.org/pypi/c3d/0.2.1) includes a script for converting C3D data to CSV format (c3d2csv).

Related

validate two excel files and create another excel file for the mismatching records by using GUI in Python Tkinter

I have a code to compare two excel/csv files and generate another excel/csv file in this file contains mismatching data. This code is execute successfully and create new excel file.
Can some one help me how to do same things in GUI in python. I have a sample diagram for this.
My Code :
import pandas as pd
import numpy as np
dftableauserver = pd.read_excel('D:\Backup\Excel File Data Validation\Tableau Server\Tableau Server.xlsx')
dftableauonline = pd.read_excel('D:\Backup\Excel File Data Validation\Tableau Online\Tableau Online.xlsx')
#print(dftableauserver.equals(dftableauonline))
comparevalues = dftableauserver.values == dftableauonline.values
#print(comparevalues)
rows,cols = np.where(comparevalues==False)
for item in zip(rows,cols):
dftableauserver.iloc[item[0],item[1]] = '{} Not Equal {}'.format(dftableauserver.iloc[item[0],item[1]],dftableauonline.iloc[item[0],item[1]])
dftableauserver.to_excel('D:\Backup\Excel File Data Validation\Validation\Validation_Output.xlsx', index=False,header=True)
print("Validation File Generated Sucessfully")
Thanks,
Allabkshu.

How to plot and analyse CAN data directly on python?

I need to analyse a lot of CAN data and want to use python for that. I recently came across the python-can library and saw that it's possible to convert .blf to .asc files.
How do I convert .blf data of CAN to .asc using python This post helped a lot.
https://stackoverflow.com/users/13525512/tranbi Can #Tranbi or anyone else help me with some example code?
This is the part I have done till now:
import can
import os
fileList = os.listdir(".\inputFiles")
for i in range(len(fileList)):
with open(os.path.join(".\inputFiles", fileList[i]), 'rb') as f_in:
log_in = can.io.BLFReader(f_in)
with open(os.path.join(".\outputFiles", os.path.splitext(fileList[i])[0] + '.asc'), 'w') as f_out:
log_out = can.io.ASCWriter(f_out)
for msg in log_in:
log_out.on_message_received(msg)
log_out.stop()
I need to either directly read data from .blf files sequentially, or convert them to .asc, correct the timestamp using the file name, combine the files, convert them to .csv and then analyse in python. Would really help if I can get a shorter route?

Export data from MSSQL to Excel 'template' saving with a new name using Python

I am racking my brain here and have read a lot of tutorials, sites, sample code, etc. Something is not clicking for me.
Here is my desired end state.
Select data from MSSQL - Sorted, not a problem
Open an Excel template (xlsx file) - Sorted, not a problem
Export data to this Excel template and saving it with a different name - PROBLEM.
What I have achieved so far: (this works)
I can extract data from DB.
I can write that data to Excel using pandas, my line of code for doing that is: pd.read_sql(script,cnxn).to_excel(filename,sheet_name="Sheet1",startrow=19,encoding="utf-8")
filename variable is a new file that I create every time the for loop runs.
What my challenge is:
The data needs to be export to a predefined template (template has formatting that must be present in every file)
I can open the file and I can write to the file, but I do not know how to save that file with a different name through every iteration of the for loop
In my for loop I use this code:
#this does not work
pd.read_sql(script,cnxn)
writer = pd.ExcelWriter(SourcePath) #opens the source document
df.to_excel(writer)
writer.save() #how to I saveas() a different file name?????
Your help would be highly appreciated.
Your method is work. The problem is you don't need to write the data into excel file right after you read the data from the database. My suggestion is first read the data into different data frame.
df1 = pd.read_sql(script)
df2 = pd.read_sql(script)
df3 = pd.read_sql(script)
You can then write all the dataframe together to a excel file. You can refer to this link.
I hope this solution can help you. Have a nice weekend

Parsing a json file using python

I have this json file which has the image name(medical images-around 7500) and its corresponding medical reports.
It is of the format:
{"IMAGE_NAME1.png": "MEDICAL_REPORT1_IN_TEXT", "IMAGE_NAME2.png": "MEDICAL_REPORT2_IN_TEXT", ...and so on for all images ...}
What I want is all the image names in the JSON file so that I can take all the images(From a database of images which is a super set of the image names in the JSON file) and make its own folder. Can someone help me with this?
I think you're looking for the json library. I haven't tested this, but I am pretty confident it will work.
import json
with open("path/to/json.json", 'r') as file:
json_data = json.load(file)
to get image names from what you described the data to look like.
image_names = list(json_data.keys())

How do I add specifically found (OCR) text into a list and write it to an excel file? [pytesseract]

I want to extract certain information from many PNG/JPEG files through pytesseract and write them into an excel file if possible.
I've figured out how to extract the text from the pictures but what I haven't figured out is:
1) How do I extract specific information instead of a whole blob of words? For example, I want the account numbers and reference numbers from each photo, nothing else.
2) How do I write these account numbers and reference numbers into an external file such as excel?
I'll attach what I've got so far below:
I've heard that using pandas dataframes was a good way to append data into columns for Excel but I'm not sure if I can do that for a task like this.
from PIL import Image
import pytesseract
import pandas as pd
pytesseract.pytesseract.tesseract_cmd = "C:\\Program Files (x86)\\Tesseract-OCR\\tesseract.exe"
im = Image.open("C:/Users/user1/desktop/scripts/ocr/example bills/pic.jpg")
content = pd.DataFrame()
text = pytesseract.image_to_string(im, lang= 'eng')
temp = pd.DataFrame({'Words':[text]})
content.append(temp)
content.head()
print(text)
writer = pd.ExcelWriter('wordstest.xlsx')
content.to_excel(writer,'Sheet1')
writer.save()
Expected Results:
An excel file with two columns, account number and reference number.
Actual Results:
An excel file with no data.
To convert a dataframe to a spreadsheet try this
content.to_csv('wordstest.csv',sep=',')
This can be opened in excel. If you need more columns just add them to the dataframe and then write the csv file
You have to filter the text that you have read from the image or find the portions of the image that you want to read before actually reading them with tesseract. For filtering the read text you can use regexes and for finding the portions in the image you'll have to use some of the computer vision algorithms that predict some portions of the image (object detection) and train them on your data.
And for adding the dataframe to excel just use pandas to_csv or to_excel methods

Categories