Home > Software design >  Creating A CSV file on ubuntu server using cocotb
Creating A CSV file on ubuntu server using cocotb

Time:11-15

Here I want to create a csv file on cocotb, but the following code is for Google Colab which is working perfectly.

import cocotb
from cocotb.triggers import Timer
import random
import pyuvm
import pandas as pd
from pandas import Series, DataFrame
import os
from google.colab import drive
drive.mount('/content/drive')
os.chdir('/content/drive/My Drive/Colab Notebooks')

Now i have generated random numbers and then append them in a list, also generated random op_code.
@cocotb.test()
async def CODE_AA(dut):
 
 listA = []
 listB = []
 listC = []
 ALU_CONTROL = ['00', '01', '10', '11'] #['0', '1', '2', '3']

for i in range(10):
 A = random.randint(0, 1000)
 listA.append(A)
await Timer(20, units = "ns")
print(A)
 
 B = random.randint(0, 1000)
 listB.append(B)
await Timer(20, units = "ns")
print(B)
 
  #C = random.randint(0, 3)
 listC.append(random.choice(ALU_CONTROL))
print(listC)
 
DICT= {'A': listA, 'B': listB, 'C': listC}
dfA = pd.DataFrame.from_dict(DICT)
dfA_Transposed = dfA.T
print(dfA)

dfA.to_csv('basic_py.csv')
DICT = {'A': listA, 'B': listB, 'C': listC}
dfA = pd.DataFrame.from_dict(DICT) 
print(dfA)

I want to make CSV file now on Ubuntu server using cocotb, This code is working perfectly on Google Colab. Kindly guide me with the issue

CodePudding user response:

You probably just want to omit importing the google drive lib:

# from google.colab import drive
# drive.mount('/content/drive')
# os.chdir('/content/drive/My Drive/Colab Notebooks')

# Change directory to somewhere you have access on the server
os.chdir('~/content/collab_notebooks')
  • Related