Skip to content
This repository has been archived by the owner on Mar 29, 2024. It is now read-only.

Commit

Permalink
update csv import
Browse files Browse the repository at this point in the history
  • Loading branch information
richiverse committed May 6, 2019
1 parent a507c3e commit 10ed5d8
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
6 changes: 4 additions & 2 deletions pandas_ext/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Versioning kept here."""
__version__ = '0.4.13'
__version__ = '0.5.01'
__license__ = "MIT"

__title__ = "pandas_ext"
Expand All @@ -15,14 +15,15 @@
del _pd

from .amazon_spectrum import to_spectrum
from ._csv import to_csv
from .px_csv import to_csv
from .excel import to_excel
from .gdrive import read_gdrive, to_gdrive
from .parquet import read_parquet, to_parquet
from .sfdc import (
read_sfdc, sfdc_metadata, patch_sfdc, async_patch_sfdc,
)
from .sql import read_sql, list_backends
from .snowflake import read_snowflake, to_snowflake



Expand All @@ -35,3 +36,4 @@
del parquet
del sfdc
del sql
del snowflake
32 changes: 32 additions & 0 deletions pandas_ext/_xml.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""Write a pandas dataframe to xml."""
import pandas as pd
from xml.sax.saxutils import escape


def to_xml(df, filename=None, mode='w'):
"""Write df to xml."""
def row_to_xml(row):
"""Row by row."""
xml = ['<item>']
for i, col_name in enumerate(row.index):
raw = row.iloc[i]
if not isinstance(raw, float) and '&' in raw:
print(raw, type(raw))
value = escape(raw) if isinstance(raw, str) else raw

xml.append(' <field name="{0}">{1}</field>'
.format(col_name, value)
)
xml.append('</item>')
return '\n'.join(xml)

res = '<?xml version="1.0" encoding="UTF-8"?>\n'
res += '\n'.join(df.apply(row_to_xml, axis=1))

if filename is None:
return res
with open(filename, mode) as f:
f.write(res)


pd.DataFrame.to_xml = to_xml
1 change: 0 additions & 1 deletion pandas_ext/amazon_spectrum.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from inspect import cleandoc

import pandas as pd
print(dir(pd))

from pandas_ext.common.utils import today
from pandas_ext.sqla_utils import schema_from_df
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def find_meta(meta):
xls=["xlwt"],
xlsx=["openpyxl", "xlsxwriter"],
snowflake=["snowflake-sqlalchemy"],
parquet=["pyarrow"],
),
long_description=README,
packages=PACKAGES,
Expand Down

0 comments on commit 10ed5d8

Please sign in to comment.