I have a text file containing two columns, but when I want to read the data using Pandas, the columns and the data are misaligned.
Here's my code for reference:
import pandas as pd
filename = r'data.txt'
#read text file into pandas DataFrame
df = pd.read_csv(
filename,
sep="\t",
skiprows=3,
names=['Frequency / MHz', 'S2,1 [SPara1]/abs,dB'],
)
df
Result:
Frequency / MHz S2,1 [SPara1]/abs,dB
0 0.1423125 -... NaN
1 0.146625 -... NaN
2 0.1509375 -... NaN
3 0.15525 -... NaN
4 0.1595625 -... NaN
... ... ...
4059 17.64675 ... NaN
4060 17.651063 ... NaN
4061 17.655375 ... NaN
4062 17.659688 ... NaN
4063 17.664 ... NaN
My sample data.txt:
Frequency / MHz S2,1 [SPara1]/abs,dB
----------------------------------------------------------------------
0.138 -0.92293553
0.1423125 -0.93264485
0.146625 -0.94201416
0.1509375 -0.95106676
0.15525 -0.95982484
0.1595625 -0.96830956
0.163875 -0.97654091
0.1681875 -0.98453781
0.1725 -0.99231804
0.1768125 -0.99989837
0.181125 -1.0072945
0.1854375 -1.0145212
0.18975 -1.0215921
0.1940625 -1.0285203
0.198375 -1.0353177
0.2026875 -1.0419956
0.207 -1.0485644
0.2113125 -1.0550339
I want the data 'NaN' to change to its original data. What should I change in my code?