當前位置: 首頁>>代碼示例>>Python>>正文


Python Series.to_csv方法代碼示例

本文整理匯總了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) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:18,代碼來源:test_io.py

示例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) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:12,代碼來源:test_io.py

示例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) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:15,代碼來源:test_io.py

示例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) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:11,代碼來源:test_io.py

示例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) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:9,代碼來源:test_io.py

示例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) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:9,代碼來源:test_io.py

示例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)) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:32,代碼來源:test_io.py

示例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) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:12,代碼來源:test_io.py

示例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) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:15,代碼來源:test_io.py

示例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) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:11,代碼來源:test_io.py

示例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) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:11,代碼來源:test_io.py

示例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) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:9,代碼來源:test_io.py


注:本文中的pandas.Series.to_csv方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。