Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
estimate-restock-quantity
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vuong Vu
estimate-restock-quantity
Commits
d8dd4dc8
Commit
d8dd4dc8
authored
Mar 18, 2024
by
vuong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add convert file
parent
e77f53d8
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
0 deletions
+42
-0
convert.py
convert.py
+42
-0
No files found.
convert.py
0 → 100644
View file @
d8dd4dc8
import
pandas
as
pd
def
csv_to_json
(
csv_file
,
json_file
):
# read csv to dataframe
df
=
pd
.
read_csv
(
csv_file
)
# Chuyển đổi DataFrame thành JSON
json_data
=
df
.
to_json
(
orient
=
'records'
)
# Save data to JSON file
with
open
(
json_file
,
'w'
)
as
f
:
f
.
write
(
json_data
)
def
csv_to_text
(
csv_file
,
text_file
):
# read csv to dataframe
df
=
pd
.
read_csv
(
csv_file
)
# Open File to write data
with
open
(
text_file
,
'w'
)
as
f
:
# Convert DataFrame into text with template "Title: value"
for
index
,
row
in
df
.
iterrows
():
for
col
in
df
.
columns
:
f
.
write
(
f"
{
col
}
:
{
row
[
col
]
}\
n
"
)
csv_file_path
=
'extra.csv'
json_file_path
=
'converted_data.json'
# convert csv to json and save
csv_to_json
(
csv_file_path
,
json_file_path
)
print
(
"Convert to JSON successfully!"
)
# # convert CSV to JSON
# json_data = csv_to_json(csv_file_path)
# print("JSON Data:")
# print(json_data)
# text_file_path = 'converted_data.txt'
# # convert csv to text
# csv_to_text(csv_file_path, text_file_path)
# print("Convert to text successfully!")
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment