Objectives
Display an electrical signal and export it as a .csv file.
Read this .csv or .xls file as an array and plot it.
Compute the mean and standard deviation of the signal. Plot its histogram with an appropriate bin size.
Theory
Pandas is a powerful and flexible Python package that allows you to work with labeled and time series data. It also provides statistics methods, enables plotting, and more. One crucial feature of Pandas is its ability to write and read Excel, CSV, and many other types of files. Functions like the Pandas read_csv() method enable you to work with files effectively. You can use them to save the data and labels from Pandas objects to a file and load them later as Pandas Series or DataFrame instances. A comma-separated values (CSV) file is a plaintext file with a .csv extension that holds tabular data. This is one of the most popular file formats for storing large amounts of data. Each row of the CSV file represents a single table row. The values in the same row are by default separated with commas, but you could change the separator to a semicolon, tab, space, or some other character.
Steps to follow
First you have to create generate a sine signal values
Save that values to a variable dat
You can use this dat to create an instance of a Pandas DataFrame.
For that you need to import Pandas
You can reverse the rows and columns of a DataFrame with the property .T:
You can save your Pandas DataFrame as a CSV file with .to_csv():
Once your data is saved in a CSV file, you’ll likely want to load and use it from time to time. You can do that with the Pandas read_csv() function:
Use pandas .plot() function to plot the read data
Use .hist() to plot the histogram of the data
Use .std() function to find the standard deviation
Use .mean() function to find the mean
Program
#importing libraries
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
# Get x values of the wave
t = np.linspace(0,1,100)
# calculating the amplitude
y = np.sin(2*np.pi*t) # calculating sine wave
dat = [t,y]
# writing the value in to data.csv
df = pd.DataFrame(data=dat,index=["Time","Amplitude"]).T
# df
df.to_csv('data.csv')
#Reading the file data.csv
df1=pd.read_csv('data.csv',index_col=0)
# df1
#Plotting the function from read value
df1.plot(x="Time",y="Amplitude")
plt.show()
# Creating histogram
df1.hist(column="Amplitude")
# Show plot
plt.show()
# Standard deviation of the value
print("Standard Deviation")
print(df1.std(0))
# Mean of the values
print("Mean")
print(df1.mean(0))
Output
Standard Deviation
Time 0.293045
Amplitude 0.707107
dtype: float64
Mean
Time 5.000000e-01
Amplitude -1.604953e-17
dtype: float64
Inference
Generated an electrical signal and exported it as a .csv file.
Read that .csv file as an array and plotted it.
Computed the mean and standard deviation of the signal. Plotted its histogram with an appropriate bin size.
Great
ReplyDeleteSimple Data Analysis with Spreadsheets is one of the easiest and most effective ways to organize, process, and interpret data for academic, business, and research purposes. Tabular Data Projects Spreadsheet applications such as Microsoft Excel and Google Sheets provide built-in tools to perform calculations, create tables, apply formulas, and visualize information using charts and graphs. Users can sort, filter, and summarize large amounts of data efficiently, making spreadsheets suitable for handling student records, sales reports, survey responses, and financial data. Features like conditional formatting, pivot tables, and basic statistical functions help users identify patterns and trends quickly. Data Science Projects for Final Year
ReplyDeleteSimple spreadsheet-based data analysis also improves decision-making by converting raw data into meaningful insights. By using formulas such as SUM, AVERAGE, COUNT, and IF conditions, users can automate repetitive calculations and reduce manual errors. Graphical representations including bar charts, pie charts, and line graphs make the analyzed data easier to understand and present. Spreadsheet tools are widely used because they require minimal programming knowledge while still offering powerful analytical capabilities. As a result, spreadsheet-based data analysis is highly valuable for beginners, students, small businesses, and researchers who need a practical and cost-effective solution for data management and reporting.