load dat in python

main.py
You can load data in Python using various libraries such as pandas, NumPy, and built-in functions. Here are a few common ways to load data:

1. Using Pandas:
```python
import pandas as pd

# Load a CSV file
df = pd.read_csv('file.csv')

# Load an Excel file
df = pd.read_excel('file.xlsx')

# Load data from a SQL database
import sqlite3
conn = sqlite3.connect('database.db')
df = pd.read_sql_query("SELECT * FROM table_name", conn)
conn.close()
446 chars
18 lines
  1. Using NumPy:
main.py
import numpy as np

# Load data from a text file
data = np.loadtxt('data.txt')

# Load data from a CSV file
data = np.genfromtxt('data.csv', delimiter=',')

# Load data from a binary file
data = np.fromfile('data.bin')
219 chars
11 lines
  1. Using Built-in functions:
main.py
# Read contents of a file
with open('file.txt', 'r') as file:
    data = file.read()

# Reading line by line in a file
with open('file.txt', 'r') as file:
    for line in file:
        print(line)
197 chars
9 lines

These are just a few examples of how you can load data in Python. The method you choose depends on the type of data you have and the format in which it is stored.

main.py
0 chars
1 lines

related categories

gistlibby LogSnag