将数据从Python导出到Excel

时间:2023-01-03 01:57:40

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

我正在尝试使用(http://jupyter.org/)将数据从Python导出到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 ?

这是我的第一个项目使用Python Any Idea有什么错误或者我可以使用的任何其他代码?

1 个解决方案

#1


0  

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.

我使用的是在线Jupyter笔记本中的Azure笔记本(https://notebooks.azure.com)。我尝试了一个我的数据框,我从Kaggle下载到导出,看起来它正在工作,下面是代码。

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.

请注意,在这里您需要通过本地系统的数据>上传菜单上传任何数据集(CSV)文件,然后我使用DF to_excel的Panda方法创建只有文件名的Excel。这将在/ library文件夹中创建文件名,然后您可以使用“数据”>“下载”来下载文件。

将数据从Python导出到Excel

Hope this will help in your scenario.

希望这对您的方案有所帮助。

#1


0  

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.

我使用的是在线Jupyter笔记本中的Azure笔记本(https://notebooks.azure.com)。我尝试了一个我的数据框,我从Kaggle下载到导出,看起来它正在工作,下面是代码。

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.

请注意,在这里您需要通过本地系统的数据>上传菜单上传任何数据集(CSV)文件,然后我使用DF to_excel的Panda方法创建只有文件名的Excel。这将在/ library文件夹中创建文件名,然后您可以使用“数据”>“下载”来下载文件。

将数据从Python导出到Excel

Hope this will help in your scenario.

希望这对您的方案有所帮助。