6 examples of 'python pandas create dataframe without index' in Python

Every line of 'python pandas create dataframe without index' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
653def set_index_post_series(df, index_name, drop, column_dtype):
654 df2 = df.drop("_partitions", axis=1).set_index("_index", drop=True)
655 df2.index.name = index_name
656 df2.columns = df2.columns.astype(column_dtype)
657 return df2
1188def test_pandas_with_index():
1189 "Output: a pandas Dataframe with an index"
1190 try:
1191 import pandas
1192
1193 df = pandas.DataFrame(
1194 [["one", 1], ["two", None]], columns=["string", "number"], index=["a", "b"]
1195 )
1196 expected = "\n".join(
1197 [
1198 " string number",
1199 "-- -------- --------",
1200 "a one 1",
1201 "b two nan",
1202 ]
1203 )
1204 result = tabulate(df, headers="keys")
1205 assert_equal(expected, result)
1206 except ImportError:
1207 print("test_pandas_with_index is skipped")
1208 raise SkipTest() # this test is optional
206def to_pandas(self):
207 return self.dataframe
41@property
42def drop(self):
43 return self._drop
39def _drop_col(self, df):
40 '''
41 Drops last column, which was added in the parsing procedure due to a
42 trailing white space for each sample in the text file
43 Arguments:
44 df: pandas dataframe
45 Return:
46 df: original df with last column dropped
47 '''
48 return df.drop(df.columns[-1], axis=1)
6def test_from_dataframe():
7 symbol = "USDJPY"
8 currency_unit = Currency.JPY
9 df = pd.DataFrame(
10 index=pd.date_range(start="2018-06-06", periods=3),
11 data=[[0, 2], [2, 4], [4, 6]],
12 columns=["ask", "bid"],
13 )
14 mkt = module.from_dataframe(df, symbol, currency_unit)
15 assert mkt.symbol == symbol
16 assert mkt.currency_unit == currency_unit
17 assert all(mkt.mid.values == [1, 3, 5])
18
19 df = pd.DataFrame(
20 index=pd.date_range(start="2018-06-06", periods=3),
21 data=[[0, 2], [2, 4], [4, 6]],
22 columns=["aaa", "bbb"],
23 )
24 col_mapping = {"aaa": "ask", "bbb": "bid"}
25 mkt = module.from_dataframe(df, symbol, currency_unit, col_mapping=col_mapping)
26 assert mkt.symbol == symbol
27 assert mkt.currency_unit == currency_unit
28 assert all(mkt.mid.values == [1, 3, 5])

Related snippets