本文整理汇总了Python中pandas.Series.to_csv方法的典型用法代码示例。如果您正苦于以下问题:Python Series.to_csv方法的具体用法?Python Series.to_csv怎么用?Python Series.to_csv使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandas.Series
的用法示例。
在下文中一共展示了Series.to_csv方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_to_csv_deprecation
# 需要导入模块: from pandas import Series [as 别名]
# 或者: from pandas.Series import to_csv [as 别名]
def test_to_csv_deprecation(self, arg, datetime_series):
# see gh-19715
with ensure_clean() as path:
if arg == "path":
kwargs = dict(path=path, header=False)
elif arg == "header":
kwargs = dict(path_or_buf=path)
else: # Both discrepancies match.
kwargs = dict(path=path)
with tm.assert_produces_warning(FutureWarning):
datetime_series.to_csv(**kwargs)
# Make sure roundtrip still works.
ts = self.read_csv(path)
assert_series_equal(datetime_series, ts, check_names=False)
示例2: test_from_csv_deprecation
# 需要导入模块: from pandas import Series [as 别名]
# 或者: from pandas.Series import to_csv [as 别名]
def test_from_csv_deprecation(self, datetime_series):
# see gh-17812
with ensure_clean() as path:
datetime_series.to_csv(path, header=False)
with tm.assert_produces_warning(FutureWarning,
check_stacklevel=False):
ts = self.read_csv(path)
depr_ts = Series.from_csv(path)
assert_series_equal(depr_ts, ts)
示例3: test_to_csv
# 需要导入模块: from pandas import Series [as 别名]
# 或者: from pandas.Series import to_csv [as 别名]
def test_to_csv(self, datetime_series):
import io
with ensure_clean() as path:
datetime_series.to_csv(path, header=False)
with io.open(path, newline=None) as f:
lines = f.readlines()
assert (lines[1] != '\n')
datetime_series.to_csv(path, index=False, header=False)
arr = np.loadtxt(path)
assert_almost_equal(arr, datetime_series.values)
示例4: test_to_csv_unicode_index
# 需要导入模块: from pandas import Series [as 别名]
# 或者: from pandas.Series import to_csv [as 别名]
def test_to_csv_unicode_index(self):
buf = StringIO()
s = Series([u("\u05d0"), "d2"], index=[u("\u05d0"), u("\u05d1")])
s.to_csv(buf, encoding="UTF-8", header=False)
buf.seek(0)
s2 = self.read_csv(buf, index_col=0, encoding="UTF-8")
assert_series_equal(s, s2)
示例5: test_to_csv_list_entries
# 需要导入模块: from pandas import Series [as 别名]
# 或者: from pandas.Series import to_csv [as 别名]
def test_to_csv_list_entries(self):
s = Series(['jack and jill', 'jesse and frank'])
split = s.str.split(r'\s+and\s+')
buf = StringIO()
split.to_csv(buf, header=False)
示例6: test_to_csv_path_is_none
# 需要导入模块: from pandas import Series [as 别名]
# 或者: from pandas.Series import to_csv [as 别名]
def test_to_csv_path_is_none(self):
# GH 8215
# Series.to_csv() was returning None, inconsistent with
# DataFrame.to_csv() which returned string
s = Series([1, 2, 3])
csv_str = s.to_csv(path_or_buf=None, header=False)
assert isinstance(csv_str, str)
示例7: test_to_csv_compression
# 需要导入模块: from pandas import Series [as 别名]
# 或者: from pandas.Series import to_csv [as 别名]
def test_to_csv_compression(self, s, encoding, compression):
with ensure_clean() as filename:
s.to_csv(filename, compression=compression, encoding=encoding,
header=True)
# test the round trip - to_csv -> read_csv
result = pd.read_csv(filename, compression=compression,
encoding=encoding, index_col=0, squeeze=True)
assert_series_equal(s, result)
# test the round trip using file handle - to_csv -> read_csv
f, _handles = _get_handle(filename, 'w', compression=compression,
encoding=encoding)
with f:
s.to_csv(f, encoding=encoding, header=True)
result = pd.read_csv(filename, compression=compression,
encoding=encoding, index_col=0, squeeze=True)
assert_series_equal(s, result)
# explicitly ensure file was compressed
with tm.decompress_file(filename, compression) as fh:
text = fh.read().decode(encoding or 'utf8')
assert s.name in text
with tm.decompress_file(filename, compression) as fh:
assert_series_equal(s, pd.read_csv(fh,
index_col=0,
squeeze=True,
encoding=encoding))
示例8: test_from_csv_deprecation
# 需要导入模块: from pandas import Series [as 别名]
# 或者: from pandas.Series import to_csv [as 别名]
def test_from_csv_deprecation(self):
# see gh-17812
with ensure_clean() as path:
self.ts.to_csv(path)
with tm.assert_produces_warning(FutureWarning,
check_stacklevel=False):
ts = self.read_csv(path)
depr_ts = Series.from_csv(path)
assert_series_equal(depr_ts, ts)
示例9: test_to_csv
# 需要导入模块: from pandas import Series [as 别名]
# 或者: from pandas.Series import to_csv [as 别名]
def test_to_csv(self):
import io
with ensure_clean() as path:
self.ts.to_csv(path)
with io.open(path, newline=None) as f:
lines = f.readlines()
assert (lines[1] != '\n')
self.ts.to_csv(path, index=False)
arr = np.loadtxt(path)
assert_almost_equal(arr, self.ts.values)
示例10: test_to_csv_unicode_index
# 需要导入模块: from pandas import Series [as 别名]
# 或者: from pandas.Series import to_csv [as 别名]
def test_to_csv_unicode_index(self):
buf = StringIO()
s = Series([u("\u05d0"), "d2"], index=[u("\u05d0"), u("\u05d1")])
s.to_csv(buf, encoding="UTF-8")
buf.seek(0)
s2 = self.read_csv(buf, index_col=0, encoding="UTF-8")
assert_series_equal(s, s2)
示例11: test_to_csv_float_format
# 需要导入模块: from pandas import Series [as 别名]
# 或者: from pandas.Series import to_csv [as 别名]
def test_to_csv_float_format(self):
with ensure_clean() as filename:
ser = Series([0.123456, 0.234567, 0.567567])
ser.to_csv(filename, float_format="%.2f")
rs = self.read_csv(filename)
xp = Series([0.12, 0.23, 0.57])
assert_series_equal(rs, xp)
示例12: test_to_csv_path_is_none
# 需要导入模块: from pandas import Series [as 别名]
# 或者: from pandas.Series import to_csv [as 别名]
def test_to_csv_path_is_none(self):
# GH 8215
# Series.to_csv() was returning None, inconsistent with
# DataFrame.to_csv() which returned string
s = Series([1, 2, 3])
csv_str = s.to_csv(path=None)
assert isinstance(csv_str, str)