“Python -Lesendatei CSV” Code-Antworten

Python las CSV

# pip install pandas 
import pandas as pd

# Read the csv file
data = pd.read_csv('data.csv')

# Print it out if you want
print(data)
Random boi

Python -Lesendatei CSV

import csv
with open('file_csv.csv', newline='') as file:
    reader = csv.reader(file)
    for row in reader:
        print(row)
Filthy Fox

CSV Python schreiben

import csv

with open('names.csv', 'w') as csvfile:
    fieldnames = ['first_name', 'last_name']
    writer = csv.DictWriter(csvfile, fieldnames=fieldnames)

    writer.writeheader()
    writer.writerow({'first_name': 'Baked', 'last_name': 'Beans'})
    writer.writerow({'first_name': 'Lovely', 'last_name': 'Spam'})
    writer.writerow({'first_name': 'Wonderful', 'last_name': 'Spam'})
Arrogant Addax

So lesen Sie eine CSV -Datei in Python

import csv
with open('some.csv', newline='') as f:
    reader = csv.reader(f)
    for row in reader:
        print(row)
Gaming Computerist

So öffnen Sie die CSV -Datei in Python

import csv

with open('example.csv') as csvfile:
    readCSV = csv.reader(csvfile, delimiter=',')
Black Backed Magpie

Python CSV -Leser

with open(r'c:\dl\FrameRecentSessions.csv') as csv_file:
    csv_reader = csv.reader(csv_file, delimiter=',')
    line_count = 0
    for row in csv_reader:
        if line_count == 0:
            print(f'Column names are {", ".join(row)}')
            line_count += 1
        else:
            print(f'\t{row[0]} works in the {row[1]} department, and was born in {row[2]}.')
            line_count += 1
    print(f'Processed {line_count} lines.')
riffrazor

Ähnliche Antworten wie “Python -Lesendatei CSV”

Fragen ähnlich wie “Python -Lesendatei CSV”

Weitere verwandte Antworten zu “Python -Lesendatei CSV” auf Python

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen