Python Forum
Searching a .txt file for a specific number and extracting the corresponding data
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Searching a .txt file for a specific number and extracting the corresponding data
#1
Hi, I am a beginner at coding and am using anaconda/jupyter notebook to code in python.

I am hoping to create a graph from a large dataset. My dataset has two columns (frequency and transmission).

I want my code to search the first column for all values of 0.6 and then pull the number from the second row(transmission) and store it an array. Aka I want all transmission values for f=0.6 in its own array.

From there I can figure out how to plot that new array of transmission values against an array I have created.

If anyon can help me do this I would really appreciate it!
Reply
#2
Can you show the code you have so far?
Reply
#3
Do you mean something like that:

>>> d = [
...     [1, 10],
...     [0.6, 20],
...     [2, 30],
...     [0.6, 40]
...     ]
>>> [row[1] for row in d if row[0] == 0.6]
[20, 40]
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#4
(Jul-26-2018, 08:34 PM)Vysero Wrote: Can you show the code you have so far?
import numpy as np
import matplotlib.pyplot as plt

data_file1 = np.loadtxt('untitled.txt',delimiter='\t')     
p = data_file1[:,][:,0]              
t = data_file1[:,][:,1]      

plt.figure(1)
plt.rcParams['figure.figsize'] = [50, 50]
plt.plot(p, t,'c')
plt.xlabel('Periodicity [microns]')
plt.ylabel('Transmission')
plt.savefig('XRectangle.png')        # Saves the plot
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Training a model to identify specific SMS types and extract relevant data? lord_of_cinder 0 254 Oct-10-2022, 04:35 AM
Last Post: lord_of_cinder
  Split excel file and write output at specific row and set sheet position DSCA 0 862 May-12-2022, 07:29 PM
Last Post: DSCA
  Searching Module to plot large data G_rizzle 0 916 Dec-06-2021, 08:00 AM
Last Post: G_rizzle
  extracting sublist from a large multiple molecular file juliocollm 2 1,603 May-25-2020, 12:49 PM
Last Post: juliocollm
  Import Excel File that Starts with Number kiki1113 1 2,496 Dec-20-2018, 07:13 PM
Last Post: Larz60+
  Extracting specific columns in an array uthongam 1 1,669 Dec-07-2018, 06:06 PM
Last Post: ichabod801
  Write specific rows from pandas dataframe to csv file pradeepkumarbe 3 4,272 Oct-18-2018, 09:33 PM
Last Post: volcano63
  extracting XML data into datframe hey_arnold 2 2,108 Jul-29-2018, 04:48 PM
Last Post: hey_arnold
  How to filter specific rows from large data file Ariane 7 7,000 Jun-29-2018, 02:43 PM
Last Post: gontajones
  Plotting climate data with NetCdf files for a specific region with coordinates fyec 3 4,332 Jun-27-2018, 12:34 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020