Python Forum
remove b due to conversion in PyQ
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
remove b due to conversion in PyQ
#7
This is my Qtable/Qlist info on datatypes:


Data columns (total 5 columns):

#   Column        Non-Null Count  Dtype

---  ------        --------------  -----

 0   Col1       5 non-null      object

1   Col2       5 non-null      object

2   Col3        5 non-null      object

3   Col3       5 non-null      object

4   Col4          5 non-null      int16

dtypes: int16(1), object(4)
I thought using lambda will help to decode only the object columns which is in bytes as I have 1 int as datatypes.


df = df.apply(lambda x: x.decode() if isinstance(x, bytes) else x)

df.to_csv (r'PATH/Out.csv',index = False, header=True)
Right now, my output is below on CSV:


Col1,Col2,Col3,Col3,Col4

[''],[b'abcdfe'],[b'ABC'],[b''],0

[''],[b'hijkl'],[b'LMNDE'],[b''],0

[''],[b'mno'],[b'YUTER'],[b''],0
I want to convert the bytes column to normal col and then write it to csv.



Am expecting csv output to be below:

Col1,Col2,Col3,Col3,Col4

,abcdfe,ABC,,0

,hijkl',LMNDE',,0

,mno',YUTER',,0
Reply


Messages In This Thread
remove b due to conversion in PyQ - by Creepy - Jul-15-2021, 08:14 PM
RE: remove b due to conversion in PyQ - by Creepy - Jul-16-2021, 04:57 PM
RE: remove b due to conversion in PyQ - by Creepy - Jul-16-2021, 07:19 PM
RE: remove b due to conversion in PyQ - by Creepy - Jul-20-2021, 06:54 PM
RE: remove b due to conversion in PyQ - by Creepy - Jul-21-2021, 05:57 PM

Forum Jump:

User Panel Messages

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