0

I used a sample of a csv program to do some tables on Jupiter notebook, I now need to download that sample csv file so I can look at it in excel, is there a way I can download the sample

I need to download lf if possible.

Here is my code:

warnings.filterwarnings("ignore")

import numpy as np
import pandas as pd
import io
import requests 

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

lf = df.sample(5000, random_state=999)

import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline 
%config InlineBackend.figure_format = 'retina'
plt.style.use("seaborn")

lf.sample(5000, random_state=999)'''
JAJ
  • 1

3 Answers3

2

You first need to convert the sample to a dataframe and then you can export it.

dframe.to_csv(“file_name.csv”)

Let me know if it works.

ebit840
  • 21
  • 3
  • i also have noticed some beforementioned posts and just have accessing to file through made simple FTP petitions for CSV Download. – user11717481 Oct 21 '22 at 16:21
1

Answer from here:

import urllib.request
urllib.request.urlretrieve("http://jupyter.com/diamond.csv", "diamond.csv")
Shōgun8
  • 482
  • 10
  • 20
1

if what you mean by download is exporting the dataframe to spreadsheet format, pandas have the function

import pandas as pd
df = pd.read_csv("diamond.csv")
# do your stuff
df.to_csv("diamond2.csv") # if you want to export to csv with different name
df.to_csv("folder/diamond2.csv") # if you want to export to csv inside existed folder
df.to_excel("diamond2.xlsx") # if you want to export to excel

The file will appear on the same directory as your jupyter notebook.

You can also specify the directory

df.to_csv('D:/folder/diamond.csv')

to check where is your current work directory, you can use

import os
print(os.getcwd())