I'm still new to python. I'm trying to import an excel doc into python but I get the filenotfounderror
This is what I'm running:
import pandas as pd
practiceset = (r'C:\Users\michael\Desktop\Work\Transpo\'Transportation2016.xlsx')
df = pd.read_excel(practiceset)
print (df)
The python file is in the same folder as the doc, so I'm confused.
Try this:
import pandas as pd
practiceset = (r'C:\Users\michael\Desktop\Work\Transpo\Transportation2016.xlsx')
df = pd.read_excel(practiceset)
print (df)
Related
I'm trying to read csv file in pandas from this url:
https://www.dropbox.com/s/uh7o7uyeghqkhoy/diabetes.csv
By doing this:
url = "https://www.dropbox.com/s/uh7o7uyeghqkhoy/diabetes.csv">
c = pd.read_csv(url)
Or by doing this:
import pandas as pd
import io
import requests
url="https://raw.githubusercontent.com/cs109/2014_data/master/countries.csv"
s=requests.get(url).content
c=pd.read_csv(io.StringIO(s.decode('utf-8')))
And i still get the same error message:
ParserError: Error tokenizing data. C error: Expected 1 fields in line 3, saw 2
Simply:
import pandas as pd
df = pd.read_csv("https://www.dropbox.com/s/uh7o7uyeghqkhoy/diabetes.csv?dl=1")
print(df)
You require a ?dl=1 at the end of your link.
Related
Add ?dl=1 to the end of the URL
import pandas as pd
url = "https://www.dropbox.com/s/uh7o7uyeghqkhoy/diabetes.csv?dl=1"
c = pd.read_csv(url)
print(c)
How to download dropbox csv file to pandas
I am trying to read an already existing excel file, and append some data in another sheet in that excel file. however, after closing the file, when i try to manually open it and do some manual calculation etc.. it's says that excel is read-only. can you please help me.
import numpy as np
import pandas as pd
import os, glob
import datetime as dt
import yfinance as yf
from openpyxl import load_workbook
ticker = "SBIN.NS"
start = dt.datetime.today() - dt.timedelta(5000)
end = dt.datetime.today()
ohlcv_data = pd.DataFrame()
temp_ticker = yf.Ticker(ticker)
ohlcv_data = temp_ticker.history(start=start,end=end,interval='1d')
writer = pd.ExcelWriter('D:/NSE/SBI.xlsx',engine='openpyxl',mode='a')
ohlcv_data.to_excel(writer, sheet_name='yahoo_data2')
writer.close()
Trying to read a xlsb file to create a DF in pandas.
import pandas as pd
a_data = pd.ExcelFile(
r'C:\\Desktop\\a.xlsb')
df_data = pd.read_excel(a_data, 'Sheet1', engine='pyxlsb')
print(df.head())
When I run the script I keep getting this error.
OSError: File contains no valid workbook part
You can use pyxlsb, all latest version of pandas support this.
Use following code:
import pandas as pd
a_data = pd.ExcelFile(r'C:\\Desktop\\a.xlsb')
df = pd.read_excel('a_data', sheet_name='Sheet1', engine='pyxlsb')
You will have to install pyxlsbfirst using command: pip install pyxlsb
Hi I am unable to read CSV file from the URL by using
import pandas as pd
import numpy as np
data_url = 'https://data.baltimorecity.gov/Financial/Real-Property-Taxes/27w9-urtv.csv'
df = pd.read_csv(data_url)
df.head()
I got an error: "not acceptable"
I also tried different codes importing "requests" but none of them worked. How do I fix this?
Your URL wasnt correct. This should work:
import pandas as pd
data_url = 'https://data.baltimorecity.gov/resource/27w9-urtv.csv'
df = pd.read_csv(data_url)
df.head()
Struggling to get xlxswriter to create multiple worksheets and use the pandas df.to_excel method to place the data in there.
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import xlsxwriter
import os as os
import sqlite3 as sql
import xlrd
path = (r'C:\Users\test1\Downloads\category.xlsx') #folder
data = pd.DataFrame()
data = pd.read_excel(path,sheetname='1')
print (data.shape)
data.head()
#create excel workbook using xlsxwriter
#workbook = xlsxwriter.Workbook('hyperlink.xlsx')
writer = ExcelWriter('hyperlink.xlsx')
data.to_excel(writer,'Sheet1')
workbook.close()