0

I have begun to learn about python / matplolib / basemap and really need some help.

My data is in an Excel workbook with the following structure:

Event Number    Date             Lat             LOn      Time (UTC)
1             02/may             14,4          -98,9      0145
                                 15,6          -99,9      0215
                                 13,6          -100,9     0245
                                 14,9          -108,8     0315              

2             26/may             15,8          -89,7      1245
                                 15,9          -90,8      1315
                                 15,7          -98,9      1345

...

How to open excel file in python?

I would like to plot multiple line joining the positions of each of the events, it is possible to do this? Have any idea how to do it?

The idea is to plot the trajectories on a particular region, for my case is Mexico.

bmu
  • 35,119
  • 13
  • 91
  • 108
user1345283
  • 645
  • 5
  • 11
  • 18

2 Answers2

2

To open an excel file in python, please see: here

That said, I think it's even easier if you just save it as a CSV file and then open using numpy.loadtxt However, this may require some reformatting of your data. You can also always build your own parser and use commas as space delimiters. If this is your idea, let me know and I can show you how to do it.

If your axes are latitude and longitude, then create an array of the latitude and longitude and plot using this

Once you have created your lat array and longitude array, your code would look like this:

import matplotlib.pyplot as plt
plt.figure()
plt.plot(lat, longitude, 'r')
Community
  • 1
  • 1
  • Thanks for the comment. I followed the suggestion you gave me and I've run into some errors. First to try this: np.loadtxt data = ('/ home / McIDAS / Documents / Data-trac / trac_prueba.txt') I get the following error: X.append (tuple ([conv (val) for (conv, val) in zip (converters, vals)])) ValueError: invalid literal for float (): Lat I guess this error is because my data array does not correspond to the data structure of numpy, if this is correct, as I can structure my data so that i can open and then plotted, using the libraries for numpy and matplotlib. – user1345283 Jan 10 '13 at 02:21
1

Pandas has facilities for loading Excel files, and it is somewhat easier that using xlrd directly. Alternatively, you can export the xls file to csv and read that in python using the csv module.

mbatchkarov
  • 15,487
  • 9
  • 60
  • 79