0

I'm trying to export data from Python using (http://jupyter.org/) to Excel

import pandas as pd
import matplotlib.pyplot as plt
from datetime import datetime
df = pd.read_csv('rr.csv') 
df['COLLISION_DATE'] = pd.to_datetime(df['COLLISION_DATE'],format='%Y%m%d')
df['week'], df['month'], df['year'],df['day'] = df['COLLISION_DATE'].dt.week, df['COLLISION_DATE'].dt.month, df['COLLISION_DATE'].dt.year,df['COLLISION_DATE'].dt.day
df = df.groupby('month').size().to_frame('Number of Accidents') 
df.plot.line()
plt.show()
df
df.to_excel('m.xlsx')

I'm getting error

ModuleNotFoundError: `No module named 'openpyxl'

this is my first project using Python Any Idea whats wrong or any other code that I can Use ?

4
  • 1
    you have to install it using pip install openpyxl, it's not provided by default Commented Oct 24, 2017 at 19:54
  • Is it possible to use online Python jupyter.org Or do I have to install it on my computer ? Commented Oct 24, 2017 at 20:04
  • I wouldn't know, sorry. but it's lightweight and very easy to install. shouldn't be a problem. Even if you're not sysadmin, you can put it in your pythonpath after downloading it. Commented Oct 24, 2017 at 20:05
  • 1
    @Ara No, the notebook at try.jupyter.org doesn't have the openpyxl module available. So you'll need to have the Python modules on your own computer. Download and install for example the Anaconda distribution. It has a user-friendly installer, and it already includes the openpyxl, jupyter, pandas and matplotlib modules right away. Commented Oct 24, 2017 at 21:23

1 Answer 1

1

I am using Azure notebook (https://notebooks.azure.com) which is in an online Jupyter notebook. I tried one my DataFrame which I downloaded from Kaggle to export and seems it's working and below is the code.

import pandas as pd
df = pd.read_csv('/home/nbuser/armenian_pubs.csv')
df.to_excel('data_set_2.xlsx')

Note that here you need to upload the any data set (CSV) file via Data > Upload menu from local system, then I used the DF to_excel of Panda method to create the Excel with just file name. This creates the file name on the /library folder and from there you can use Data > Download to download the file.

enter image description here

Hope this will help in your scenario.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.