txt

separate a .txt file into two columns using pandas

separate a .txt file into two columns using pandas Question: I have a .txt file, without header. I am going to separate into two column with header X and Y that is ordered like this: enter image description here I have read text file into pandas: How can I have data frame with two column …

Total answers: 1

Convert pandas to txt in google colab

Convert pandas to txt in google colab Question: I have a dataset which called preprocessed_sample in the following format preprocessed_sample.ftr.zstd and I am opening it using the following code df = pd.read_feather(filepath) The output looks something like that index text 0 0 i really dont come across how i actually am an… 1 1 music …

Total answers: 2

How to reduce computational cost with Regex function

How to reduce computational cost with Regex function Question: I am trying to use regex to extract sentences containing specific words, and sentences before and next to them. My code works, but it takes 20 seconds for each txt and I have about a million txt files. Is it possible to get the same result …

Total answers: 2

How to remove the line where a specific string is found in a .txt file?

How to remove the line where a specific string is found in a .txt file? Question: import os word_to_replace, replacement_word = "", "" if (os.path.isfile(‘data_association/names.txt’)): word_file_path = ‘data_association/names.txt’ else: open(‘data_association/names.txt’, "w") word_file_path = ‘data_association/names.txt’ word = "Claudio" with open(word_file_path) as f: lineas = [linea.strip() for linea in f.readlines()] numero = None if word in lineas: …

Total answers: 1

Replace a string identified in a specific line of a .txt file by another string

Replace a string identified in a specific line of a .txt file by another string Question: import re, os def replace_one_line_content_with_other(input_text): word_to_replace, replacement_word = "", "" if (os.path.isfile(‘data_association/names.txt’)): word_file_path = ‘data_association/names.txt’ else: open(‘data_association/names.txt’, "w") word_file_path = ‘data_association/names.txt’ #name_capture_pattern = r"([A-Z][wí]+s*(?i:del|des*el|de)s*[A-Z]w+)" name_capture_pattern = r"((?:w+))?" regex_pattern = r"(?i:nos*es)s*" + name_capture_pattern + r"s*(?i:sinos*ques*es)s*" + name_capture_pattern n0 = re.search(regex_pattern, …

Total answers: 1

replace specific string in a txt file, but only in certain lines

replace specific string in a txt file, but only in certain lines Question: txt file with 40000 lines. In each lines are comma seperated numbers. I want to remove a specific number in the lines 36000 to 39000. For example number 233. But i dont want to remove the string from number 23341. Here is …

Total answers: 2

read from txt file and convert into dataframe in python

read from txt file and convert into dataframe in python Question: I have a txt file as following: sub_ID: [‘sub-01′,’sub-02’] ses_ID: [‘ses-01′,’ses-01’] mean: [0.3456,0.446] I want to read this and convert it to a dataframe such as in the image -don’t mind the values in mean_e_field column, it’s just an example. the values should be …

Total answers: 1

creating a leaderboard for noughts and crosses game

creating a leaderboard for noughts and crosses game Question: {"Bob": 50,"Jane": 2,"Sarah": 5, "Amelia": 20} I have a txt file like this and I wrote a code to be able to get different players name and score that will be saved to the dictionary from highest to lowest.but when ever a new player saves their …

Total answers: 1

How do you pull specific information out of a text file? Python

How do you pull specific information out of a text file? Python Question: Here is an example of some of the information in the text file: Ticker : Ticker representing the company | Company: Name | Title: Position of trader | Trade Type: Buy or sell | Value: Monetary value Ticker : AKUS | Company: …

Total answers: 2