Python Forum
Want to remove the text from a particular column in excel
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Want to remove the text from a particular column in excel
#1
Data looks like when I open this csv in Notepad.
I want to replace the "magneticfields\nD" with nothing in the Magnetic Declination column.

data['Magnetic Declination'] = data['Magnetic Declination'].apply(lambda x: x.replace(r"magneticFields\nD ", ""))


import pandas as pd
import re
data = pd.read_csv("magnetic_declination_australia_1.csv") 
data.head()
data['Magnetic Declination'] = data['Magnetic Declination'].apply(lambda x: x.replace(r"magneticFields\nD     ", ""))
data.head()
can anyone one help how to fixed this? csv file and code are attached.

Attached Files

.py   c-1.py (Size: 248 bytes / Downloads: 285)
.csv   magnetic_declination_australia_1.csv (Size: 3.49 KB / Downloads: 308)
Reply


Messages In This Thread
Want to remove the text from a particular column in excel - by shantanu97 - Jul-05-2021, 08:14 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Thumbs Up Need to compare the Excel file name with a directory text file. veeran1991 1 1,166 Dec-15-2022, 04:32 PM
Last Post: Larz60+
  How to remove footer from PDF when extracting to text jh67 3 5,240 Dec-13-2022, 06:52 AM
Last Post: DPaul
  How to remove patterns of characters from text aaander 4 1,169 Nov-19-2022, 03:34 PM
Last Post: snippsat
  Two text files, want to add a column value zxcv101 8 1,987 Jun-20-2022, 03:06 PM
Last Post: deanhystad
  How to format Excel column with comma? dee 0 1,399 Jun-13-2022, 10:11 PM
Last Post: dee
  Appending Excel column value as CSV file name sh1704 0 1,322 Feb-06-2022, 10:32 PM
Last Post: sh1704
  How to remove a column or two columns in a correlation heatmap? lulu43366 3 5,321 Sep-30-2021, 03:47 PM
Last Post: lulu43366
  beginner text formatting single line to column jafrost 4 3,257 Apr-28-2021, 07:03 PM
Last Post: jafrost
  More elegant way to remove time from text lines. Pedroski55 6 4,010 Apr-25-2021, 03:18 PM
Last Post: perfringo
  Copy column from one existing excel file to another file mkujawsk 0 5,723 Apr-14-2021, 06:33 PM
Last Post: mkujawsk

Forum Jump:

User Panel Messages

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