Wednesday, 27 May 2020

Reading CSV files without using any library | Python

Code: (Note: It will work only if you open your file with variable e) li=[]; for i in e: i=i.replace("\n","").split(","); li.append(i); e.close() Note the values are float , but in above list li , those are stored as string , you can further type cast to float using this below code: (Be careful in converting string to float , the first row can not be converted into float as those are column names , for rest of the rows you can perform conversion) li=[]; temp=0; for i in e: if(temp!=0): i=i.replace("\n","").split(","); gi=[]; for j in i: gi.append(float(j)); li.append(gi); else: i=i.replace("\n","").split(","); li.append(i); temp+=1; e.close() Python for beginners:



Post a comment

Popular Posts


Android (21) AngularJS (1) Assembly Language (2) Books (10) C (75) C# (4) C++ (81) Course (1) Data Strucures (4) Downloads (1) Engineering (13) FPL (17) Hadoop (1) HTML&CSS (38) IS (25) Java (87) Leet Code (4) PHP (20) Projects (1) Python (218) R (69) Selenium Webdriver (2) Software (14) SQL (27)