1

To generate a csv file where each column is a data of sine wave of frequency 1 Hz, 2 Hz, 3Hz, 4Hz, 5Hz, 6Hz and 7 Hz. The amplitude is one volt. There should be 100 points in one cycle and thus 700 points in seven waves.

Mikhail Berlyant
  • 165,386
  • 8
  • 154
  • 230
Uday
  • 57
  • 12

1 Answers1

3

Here is how I will go about it:

import pandas as pd
import numpy as np

freqs = list(range(1, 9))
time = np.linspace(0, 2*np.pi, 100)
data = {f"{freq}Hz": np.sin(2 * np.pi * freq * time) for freq in freqs}

df = pd.DataFrame(data)
df.head()

    

enter image description here

quest
  • 3,576
  • 2
  • 16
  • 26
  • can we add sampling points to the code. If so, does the pandas DataFrame hold columns with different lengths? Kindly clarify my doubts@quest – Uday Mar 04 '22 at 12:11
  • All DataFrames columns must have the same length. You can append NAs to the ones with fewer values. you can modify `time = np.linspace(0, 2*np.pi, 100)` to the times you need values at. you can also have different times for different frequencies. – quest Mar 05 '22 at 07:03