0

I am having data in excel and reading as below and i am trying to convert all data to string-

import pandas as pd
df=pd.read_excel('excel')
df.fillna('(Null)').astype(str)

even though i convert to string using astype(str), but in some case, i get float values as below(67.0) and how do i avoid this keeping just as string '67'-

  Name  id
0   A   123
1   B   67.0
2   C   30
3   D   40
4   E   50
5
  • 3
    How working df=pd.read_excel('excel', dtype=str) ? Commented Jul 26, 2021 at 7:17
  • Problem 67.0 should be float value in input file, so after converting to string get 67.0 to '67.0' Commented Jul 26, 2021 at 7:18
  • @jezrael thanks. right now i have only column id, but how do i avoid this problem dynamically[suppose new column coming in the input file].basically all columns in input file convert to string properly. i will try df=pd.read_excel('excel', dtype=str) Commented Jul 26, 2021 at 7:21
  • @J_Coder is your problem solved? Commented Jul 26, 2021 at 7:35
  • df=pd.read_excel('excel', dtype=str) works fine Commented Jul 26, 2021 at 7:36

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.