Series object has no split attribute - reading in data from text file

1753
August 11, 2017, at 00:20 AM

I am reading in data from a .txt file that looks like the following, and I am extracting the third item in each of the brackets with the code that is at the bottom.

With the line, data = data.iloc[0, ::4], I was removing 3 out of every 4 data points (I think).

However, now I am trying to keep every data points. So when I remove the line; data = data.iloc[0, ::4], I receive the following error:

"'Series' object has no attribute 'split'", 'occurred at index 0'

I don't understand why removing that line will give me the error that I am receiving. In short, I would like to extract every third item from each bracket, and store it in a pandas DataFrame. But when I try to remove the line, data = data.iloc[0, ::4], I get the error thrown (as shown above).

Thanks for the support!

data = pd.read_csv("C:\\Users\\Desktop\\data_test9.txt", sep="\[|\]\[|\]",engine = 'python', header = None)
data = data.iloc[0, ::4]
data = data.astype(str).apply(lambda x: x.split(',')[-1]).astype(float)
data.pop(0)
xar = range(len(data)
yar = pd.DataFrame(data)

Piece of Data:

[0.0, -0.01953125, -0.0009765625][0.0, -0.01953125, -0.0009765625][0.0, -0.01953125, -0.0009765625][0.0, -0.01953125, -0.0009765625][0.0078125, -0.912109375, -0.00390625][0.0078125, -0.912109375, -0.00390625][0.0078125, -0.912109375, -0.00390625][0.0078125, -0.912109375, -0.00390625][0.0078125, -0.912109375, -0.00390625][0.0078125, -0.912109375, -0.00390625][0.0078125, -0.912109375, -0.00390625][0.0078125, -0.912109375, -0.00390625][0.0087890625, -0.978515625, -0.00390625][0.0087890625, -0.978515625, -0.00390625][0.0087890625, -0.978515625, -0.00390625][0.0087890625, -0.978515625, -0.00390625][0.0087890625, -0.978515625, -0.00390625][0.0078125, -0.9521484375, -0.0029296875][0.0078125, -0.9521484375, -0.0029296875][0.0078125, -0.9521484375, -0.0029296875][0.0078125, -0.9521484375, -0.0029296875][0.0078125, -0.9521484375, -0.0029296875][0.0078125, -0.9521484375, -0.0029296875][0.0078125, -0.9521484375, -0.0029296875][0.0078125, -0.9521484375, -0.0029296875][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.955078125, -0.00390625][0.0078125, -0.955078125, -0.00390625][0.0078125, -0.955078125, -0.00390625][0.0078125, -0.955078125, -0.00390625][0.0078125, -0.955078125, -0.00390625][0.0078125, -0.955078125, -0.00390625][0.0078125, -0.955078125, -0.00390625][0.0078125, -0.955078125, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.0029296875][0.0078125, -0.9560546875, -0.0029296875][0.0078125, -0.9560546875, -0.0029296875][0.0078125, -0.9560546875, -0.0029296875][0.0078125, -0.9560546875, -0.0029296875][0.0078125, -0.9560546875, -0.0029296875][0.0078125, -0.9560546875, -0.0029296875][0.0078125, -0.9560546875, -0.0048828125][0.0078125, -0.9560546875, -0.0048828125][0.0078125, -0.9560546875, -0.0048828125][0.0078125, -0.9560546875, -0.0048828125][0.0078125, -0.9560546875, -0.0048828125][0.0078125, -0.9560546875, -0.0048828125][0.0078125, -0.9560546875, -0.0048828125][0.0078125, -0.9560546875, -0.0048828125][0.0087890625, -0.9560546875, -0.0029296875][0.0087890625, -0.9560546875, -0.0029296875][0.0087890625, -0.9560546875, -0.0029296875][0.0087890625, -0.9560546875, -0.0029296875][0.0087890625, -0.9560546875, -0.0029296875][0.0087890625, -0.9560546875, -0.0029296875][0.0087890625, -0.9560546875, -0.0029296875][0.0087890625, -0.9560546875, -0.0029296875][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.0029296875][0.0078125, -0.9560546875, -0.0029296875][0.0078125, -0.9560546875, -0.0029296875][0.0078125, -0.9560546875, -0.0029296875][0.0078125, -0.9560546875, -0.0029296875][0.0078125, -0.9560546875, -0.0029296875][0.0078125, -0.9560546875, -0.0029296875][0.0068359375, -0.9560546875, -0.00390625][0.0068359375, -0.9560546875, -0.00390625][0.0068359375, -0.9560546875, -0.00390625][0.0068359375, -0.9560546875, -0.00390625][0.0068359375, -0.9560546875, -0.00390625][0.0068359375, -0.9560546875, -0.00390625][0.0068359375, -0.9560546875, -0.00390625][0.0068359375, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625][0.0078125, -0.9560546875, -0.00390625]

Edit 1: My data is being saved as follows:

while True:
    delay(DELAY_INTERVAL)
    file = open("C:\\Users\\Desktop\\demo3.txt", "a")
    file.writelines(str(convert(readField())))
    file.flush()
    file.close()
Answer 1

Because data is a pd.DataFrame, so when you .apply a function to it, it passes a pd.Series as the argument to the function. pd.Series doesn't have a .split method. When you do:

data = data.iloc[0, ::4]

You are selecting the first row and every four columns, starting with the first. This *returns a pd.Series. So consider:

In [16]: df
Out[16]:
     a   b   c   d   e
0  -10  17  17  14 -10
1    2  10   0   4  -5
2   16  10   1  -9  -6
3   12  -6  10   5   3
4    9  10  -4  10   3
5   -8  16   4  17   0
6    9  12   4  17  -5
7   19  17   9   2  19
8    1   4  10  10  12
9   12  -1   9  -5  10
10  -1  -3   4  11   5
11  19   4   6  16   3
12   5  19  -1   1  15
13  18   2  15   0   7
14   3  10  15   6  15
15   8  12   3  -6   8
16  14   0  -3   6   2
17  -1  -5  -5  -3  16
18  -2  12  17  17  13
19  18   4  19  14   4
In [17]: df.iloc[0, ::4]
Out[17]:
a   -10
e   -10
Name: 0, dtype: int64
In [18]: type(df.iloc[0, ::4])
Out[18]: pandas.core.series.Series

Now, when you .apply a function to a series it passes each value in the series to the function, which is why your lambda works, since each value is a str, and strings do have a .split method.

So, perhaps you want:

In [19]: df.iloc[::4,:]
Out[19]:
     a   b   c   d   e
0  -10  17  17  14 -10
4    9  10  -4  10   3
8    1   4  10  10  12
12   5  19  -1   1  15
16  14   0  -3   6   2
In [20]: type(df.iloc[::4,:])
Out[20]: pandas.core.frame.DataFrame

Which selects every four rows, and returns a data-frame.

Rent Charter Buses Company
READ ALSO
Google Instant App - How to be go about automating with Appium?

Google Instant App - How to be go about automating with Appium?

We understand that the app needs to be launched by a browser and then a app container comes up with the cached appHowever, we don't know how to move the handle from the browser the app container

285
What is an efficient way to splice one binary input into another at an arbitrary bit number using Java without relying on parseInt?

What is an efficient way to splice one binary input into another at an arbitrary bit number using Java without relying on parseInt?

I am trying make a function in Java to splice one binary input into another using Java at the bit level as opposed to a byte levelFor example splicing "00000000" into "11111111" a position 3 would produce "1110000000011111"

214
Where to put c3p0 dependency in Tomcat Container

Where to put c3p0 dependency in Tomcat Container

I was under the impression that the libraries for both the database driver (postgres-xx

377
SQLiteDatabase.rawQuery(sql,new String[name,age,null]}) one argument doesn't matter

SQLiteDatabase.rawQuery(sql,new String[name,age,null]}) one argument doesn't matter

I have a user interface in my Android app that allows users to choose from sqlite database what he/she wants to seeFor example user can choose to see male contacts, but the user can also choose "doesn't matter" to see both male and female

346