The code that uses Pandas to output the contents of CSV will cause the numerical value to deviate from the header part written in Japanese.

Asked 2 years ago, Updated 2 years ago, 417 views

I wrote the code to output the data saved as csv in Python using pandas.
However, when I try to output the results, the header part written in Japanese and the numerical value are out of alignment.

As I touched it, I realized that if you type the header in English and the csv header in English, you will get a neatly aligned table.Can you arrange the headers neatly in Japanese?I also use Windows.Is there a problem with this?

csv code:

Name, Korean, Mathematics, English, Science, Society
A-thick, 83, 89, 76, 97, 76
B-suke, 66, 93, 75, 88, 76
C-child, 100, 84, 96, 82, 94
Duro, 60, 73, 63, 52, 70
E Beauty, 92, 62, 84, 80, 78
F vegetables, 96, 92, 94, 92, 90

source code:

import pandas as pd 

df = pd.read_csv("test.csv")

print(df)

python python3 windows pandas

2022-09-30 21:51

1 Answers

@metropolis-san I heard that it was resolved in the comment, and based on that, I answered as a community wiki.

Status at Question Time:

>>import pandas as pd
>>
>>>df=pd.read_csv("test.csv")
>>
>>print(df)
   Naming Language Mathematics English Science Society
0 A thick 838976 9776
1B-mediated 6693758876
2 C child 10084 96 8294
3Duro 6073 63 5270
4E Beauty 926284 8078
5 F veggies 96 92 94 92 90

Comment Application Results:

>>pd.set_option('display.unicode.east_asian_width', True)
>>print(df)
  Naming Language Mathematics English Science Society
0 A thick 838976 9776
1B-mediated 6693758876
2 C child 10084 96 8294
3Duro 6073 63 5270
4E Beauty 926284 8078
5 F veggies 96 92 94 92 90

Comment related specification destination:
Unicode formatting-Options and settings
It contains descriptions of additional options for characters with ambiguous width, such as twice the display performance.


2022-09-30 21:51

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.