xxxxxxxxxx
# this is pandas in python
import pandas as pd
dic={'name':["mark",'ellon'],
'roll_no':[32,24]}
df=pd.DataFrame(dic)
print(df)
xxxxxxxxxx
d = {'col1': [1, 2], 'col2': [3, 4]}
>>> df = pd.DataFrame(data=d)
>>> df
col1 col2
0 1 3
1 2 4
xxxxxxxxxx
If you use Anaconda then it is preinstalled
otherwise: pip install pandas
import pandas as pd
pd.__version__
xxxxxxxxxx
import pandas as pd
data = {
"calories" : [420, 380, 390],
"duration" : [50, 40, 45]
}
df = pd.DataFrame(data)
print(df)
xxxxxxxxxx
d = {'col1': [1, 2], 'col2': [3, 4]}
>>> df = pd.DataFrame(data=d)
>>> df
col1 col2
0 1 3
1 2 4
xxxxxxxxxx
df = pd.DataFrame(
.: {
"A": ["foo", "bar", "foo", "bar", "foo", "bar", "foo", "foo"], .:
"B": ["one", "one", "two", "three", "two", "two", "one", "three"], .:
"C": np.random.randn(8), .:
"D": np.random.randn(8), .:
.: }
.: )
.:
In [88]: df
Out[88]:
A B C D
0 foo one 1.346061 -1.577585
1 bar one 1.511763 0.396823
2 foo two 1.627081 -0.105381
3 bar three -0.990582 -0.532532
4 foo two -0.441652 1.453749
5 bar two 1.211526 1.208843
6 foo one 0.268520 -0.080952
7 foo three 0.024580 -0.264610
xxxxxxxxxx
import boto3
import pandas as pd
def store_csv_data_in_dynamodb(table_name, csv_file_path):
# Initialize DynamoDB client
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table(table_name)
# Read CSV file using pandas
csv_data = pd.read_csv(csv_file_path)
# Convert DataFrame to a list of dictionaries
items = csv_data.to_dict('records')
# Batch write items in batches of 25 (DynamoDB limit)
with table.batch_writer() as batch:
for item in items:
batch.put_item(Item=item)
print("CSV data stored in DynamoDB successfully.")
# Usage example
table_name = 'your-dynamodb-table-name'
csv_file_path = 'path/to/your/csv/file.csv'
store_csv_data_in_dynamodb(table_name, csv_file_path)