Getting rid of the 'b' in front of Python strings
You have to decode x
into bytes and append the returning value to the fixedtimeslist
list.
for x in timeslist:
fixedtimeslist.append(x.decode('utf-8'))
How do I remove bytestrings left over from decompression from a string?
I am guessing that you mistakenly assigned the above byte string “sentence” to an object of type str
. Instead, it needs to be assigned to a byte string object and interpret it as a sequence of UTF-8 bytes. Compare:
b = b'... known as \xe2\x80\x9ccomorbidity\xe2\x80\x9d and ...'
s = b.decode('utf-8')
print(b)
# b'... known as \xe2\x80\x9ccomorbidity\xe2\x80\x9d and ...'
print(s)
# ... known as “comorbidity” and ...
Either way, the issue is unrelated to compression: a lossless compression (such as bzip2) roundtrip never changes the data:
print(bz2.decompress(bz2.compress(b)).decode('utf-8'))
# ... known as “comorbidity” and ...
Related Topics
Creating a New Dataframe Column by Comparing Strings of Two Unequal Dataframes
Get Max Value Comparing Multiple Columns and Return Specific Values
How to Read a Column Without Header from CSV and Save the Output in a Txt File Using Python
How to Convert a Datetime Object to Milliseconds Since Epoch (Unix Time) in Python
Find Matching Rows in 2 Dimensional Numpy Array
What Else Do I Need for Codehs 8.3.8: Word Ladder
How to Write a Python Script That Can Read Doc/Docx Files and Convert Them to Txt
Reading an Excel Named Range into a Pandas Dataframe
Matplotlib: Attributeerror: 'Axessubplot' Object Has No Attribute 'Add_Axes'
Typing Greek Letters etc. in Plots
How to Create Dynamic Workflows in Airflow
Pyspark Data Frame Converting False and True to 0 and 1
How to Make Tkinter Frames in a Loop and Update Object Values
How to Check for an Exact Word in a String in Python
Finding an Exact Substring in a String in Python
How to Display the Value of the Bar on Each Bar With Pyplot.Barh()
How to Do This Horizontally Instead of Vertically in Python
Accuracy Score Valueerror: Can't Handle Mix of Binary and Continuous Target