Python Forum
my first code, please correct
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
my first code, please correct
#1
hi Python community
I had gone through several Python tutorials before I sat down today to writing my first code

can you judge it, please? I use Colaboratory; how to allow it to access the excel files?
#preliminary steps
import numpy as np
import pandas as pd
import matplotlib as plt
import statsmodels as sm
data = pd.read_csv("portfolios.csv") 
bm = pd.read_csv("bookToMarket.csv") 
me = pd.read_csv("marketEquity.csv") 

#Extract 99 assets and assign them to a variable called assets.
for column in data:
    print(column [1:99])

#Obtain the number of rows and columns of assets and store results as rr and cc
#respectively.
rr = sheet.max_row
cc = sheet.max_column

#For each month in the data, sort the returns on the 99 assets based on the book-to- market ratio of those assets 
for column[1:99] in bm:
  assets_sorted = sorted()
for column[1:99] in me:
  me_sorted = sorted()

# placing the first 3 rows into a docstring
for row[:3] in assets_sorted:
  docstring()

for row[:3] in me_sorted:
  docstring()
Reply
#2
Here is a snippet where I read an excel spreadsheet stored on my google drive, using colab. Adjust as needed.
from google.colab import drive
drive.mount('/content/drive')
column_names = ['Rank','Interview_Score','Scale','Name','ID','Degree','MedSchool','Zone','Grad','Step1','Step2','Sex','Couples','Couple_Prog','NA','Comment']
df = pd.read_excel(r'/content/drive/My Drive/ia1.xlsx', header=None)
Reply
#3
thanks what about the rest of my code?
Reply
#4
(Nov-16-2020, 10:10 AM)robboc91 Wrote: hi Python community
I had gone through several Python tutorials before I sat down today to writing my first code

can you judge it, please? I use Colaboratory; how to allow it to access the excel files?
#preliminary steps
import numpy as np
import pandas as pd
import matplotlib as plt
import statsmodels as sm
data = pd.read_csv("portfolios.csv") 
bm = pd.read_csv("bookToMarket.csv") 
me = pd.read_csv("marketEquity.csv") 

#Extract 99 assets and assign them to a variable called assets.
for column in data:
    print(column [1:99])

#Obtain the number of rows and columns of assets and store results as rr and cc
#respectively.
rr = sheet.max_row
cc = sheet.max_column

#For each month in the data, sort the returns on the 99 assets based on the book-to- market ratio of those assets 
for column[1:99] in bm:
  assets_sorted = sorted()
for column[1:99] in me:
  me_sorted = sorted()

# placing the first 3 rows into a docstring
for row[:3] in assets_sorted:
  docstring()

for row[:3] in me_sorted:
  docstring()


i can't figure out the answer based on what you wrote

i change the code
data = pd.read_csv('C:/Users/YOU/Desktop/python/bbing1234-attachments/portfolios.csv') 
but i dont know why it fails to read it Cry Cry
Reply
#5
I see you are using Google Colab, have you followed the instructions to make your files accessible to it?

https://colab.research.google.com/notebooks/io.ipynb

Since the Python code in Google Colab runs on Google’s computers, you’ll need to find some way to transfer your files to their computers as described there, or you will need to run Python locally on the same computer where you have your data files.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Correct the algorithm of image filter code saoko 6 2,000 May-08-2022, 05:06 PM
Last Post: saoko
  Getting the error like function not defined .. suggest correct code raghava 1 2,048 Feb-04-2020, 11:20 PM
Last Post: micseydel
  The code seems correct but my files aren't getting deleted taffylim69 1 2,057 Feb-03-2019, 11:00 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020