Python Forum
import columns of data from local csv file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
import columns of data from local csv file
Hello I am a newbie in python, but I need to write some python code in another software.
I need to import two csv files, each of them has 200 columns of data.

The attached screenshot shows what I have done so far, it successfully created 400 empty attributes, but while importing all columns of data, it seemed only worked for the first column of the first file as shown below. I do not know what is wrong with my nested for loops.

The spreadsheet in the back of my script interface is just the result of importing data into my Houdini software.

And I also attach my code as follows:

import hou
import csv
import os

node = hou.pwd()
geo = node.geometry()

for i in range(200):
directory = node.evalParm('directory')
maxrows = node.evalParm('maxrows')

def main():
    if not directory: return
    if not os.path.isdir(directory): return
    files = []
    for name in os.listdir(directory):
        if name.endswith('.csv'):
    with open(files[0]) as fs:
        readers = csv.reader(fs,delimiter=',')
        for j in range(200):
            for row in readers:
                point = geo.createPoint()
    with open(files[1]) as fw:
        readerw = csv.reader(fw,delimiter=',')
        for k in range(200):
            for row in readerw:
                point = geo.createPoint()

[Image: Screenshot-61.png]
You can use pandas data frame to import these csv or excel files
use pandas read_csv()

import pandas as pd
df = pd.read_csv ('data.csv')

Use your filename with full path instead of 'data.csv'

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to import an xml file to Pandas sjhazard 0 1,743 Jun-08-2021, 08:19 PM
Last Post: sjhazard
  pandas.to_datetime: Combine data from 2 columns ju21878436312 1 1,874 Feb-20-2021, 08:25 PM
Last Post: perfringo
  how to filter data frame dynamically with the columns psahay 0 1,872 Aug-24-2020, 01:10 PM
Last Post: psahay
  Can the data types be different for different columns? Robotguy 2 1,600 Aug-19-2020, 09:24 PM
Last Post: Robotguy
  Unable to import data from Stata-press website Salahaddin 1 1,763 Jun-08-2020, 04:23 AM
Last Post: buran
  Import Excel File that Starts with Number kiki1113 1 2,571 Dec-20-2018, 07:13 PM
Last Post: Larz60+
  Trying to import JSON data into Python/Pandas DataFrame then edit then write CSV Rhubear 0 3,558 Jul-23-2018, 09:50 PM
Last Post: Rhubear
  manipulating .csv file into columns of selected data Karen_Masila 2 2,367 Feb-14-2018, 06:50 AM
Last Post: Karen_Masila
  Replacing values for specific columns in Panda data structure Padowan 1 14,142 Nov-27-2017, 08:21 PM
Last Post: Padowan
  import/use data from text files MichealPeterson 1 2,803 Jun-28-2017, 08:51 AM
Last Post: buran

Forum Jump:

User Panel Messages

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