1

i just study pandas two days, i read a csv example file, and output every line, it like this:

              a     b     c    d     e    f     g
     0  1980/81  1182  5408  292  7248  174  2212
     1  1981/82  1098  5112  257  7316  242  1936
     2  1982/83  1156  5701  330  8567  124  1802
     3  1983/84   993  4265  391  8905  141  1078
     4  1984/85  1182  5364  217  5813  343  4313

this is my code:

df = pd.read_csv('uk_rain_2014.csv', header=0)
df.columns = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
print df.head(5)

how can i do to print every like this:

         a     b     c    d     e    f     g
   1980/81  1182  5408  292  7248  174  2212
   1981/82  1098  5112  257  7316  242  1936
   1982/83  1156  5701  330  8567  124  1802
   1983/84   993  4265  391  8905  141  1078
   1984/85  1182  5364  217  5813  343  4313
0

1 Answer 1

0

Let's try this:

print df.to_string(index=False)

Output:

a     b     c    d     e    f     g
1980/81  1182  5408  292  7248  174  2212
1981/82  1098  5112  257  7316  242  1936
1982/83  1156  5701  330  8567  124  1802
1983/84   993  4265  391  8905  141  1078
1984/85  1182  5364  217  5813  343  4313

OR

print(df.to_csv(sep='\t',index=False))

Output:

a       b       c       d   e       f   g
1980/81 1182    5408    292 7248    174 2212
1981/82 1098    5112    257 7316    242 1936
1982/83 1156    5701    330 8567    124 1802
1983/84 993     4265    391 8905    141 1078
1984/85 1182    5364    217 5813    343 4313
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.