1

Trying to use a small example to explain my case:

df = pd.DataFrame([[1,1],[1,2],[1,3],[1,4]],columns=['A', 'B'])
d1 = df['B'].apply(lambda x: '{0:0>3}'.format(x))
df['B'] = d1
df.head()
df.to_csv()

I want to save changed df into a new csv file, which should be like:

Out[28]: A    B
      0  1  001
      1  1  002
      2  1  003
      3  1  004

But after saved it used df.to_csv(), the new data file has no changes:

Out[32]: 
   A  B
0  1  1
1  1  2
2  1  3
3  1  4

Anyone could happy to tell how to fix it? many thanks!

10
  • how are you viewing the file? Commented Jan 30, 2018 at 16:24
  • yes, I can viewed the new file which is same as the original one... Commented Jan 30, 2018 at 17:16
  • I didn't ask if you could view the file. I asked how you were viewing the file. Commented Jan 30, 2018 at 17:21
  • read this while you're at it: stackoverflow.com/questions/20109391/… Commented Jan 30, 2018 at 17:22
  • Updated the question, thanks. Commented Jan 30, 2018 at 20:17

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.